A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Date Problem Help Needed, Please



 
 
Thread Tools Display Modes
  #1  
Old October 26th, 2004, 07:15 PM
Dave Elliott
external usenet poster
 
Posts: n/a
Default Date Problem Help Needed, Please

I have a form where I enter an employees payroll time with the date criteria
for there payroll week.
The payroll week runs Thursday Thru Wednesday. See Code Below. On the form
there is a control
named WorkDate with it's control set to Work Date and this is the date
between the beginning and ending date
that calculates when they get paid, i.e. if there time is entered between
the two dates, they will get paid.
The Text Box where this code below is located is named Text999
If the date entered is not between these two dates, (Work Date control) or
name WorkDate
I need a message box to appear telling me so.
How can I do this?



=Format(CDate(Date())-(Weekday(CDate(Date())))-2,"m/d/yy") & "-" &
Format(CDate(Date())-(Weekday(CDate(Date())))+4,"m/d/yy")


  #2  
Old October 27th, 2004, 01:57 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Tue, 26 Oct 2004 18:15:20 GMT, "Dave Elliott"
wrote:

I have a form where I enter an employees payroll time with the date criteria
for there payroll week.
The payroll week runs Thursday Thru Wednesday. See Code Below. On the form
there is a control
named WorkDate with it's control set to Work Date and this is the date
between the beginning and ending date
that calculates when they get paid, i.e. if there time is entered between
the two dates, they will get paid.


I'm confused. Is the data in WorkDate a date value, or a number of
days, or what?

The Text Box where this code below is located is named Text999
If the date entered is not between these two dates, (Work Date control) or
name WorkDate
I need a message box to appear telling me so.
How can I do this?



=Format(CDate(Date())-(Weekday(CDate(Date())))-2,"m/d/yy") & "-" &
Format(CDate(Date())-(Weekday(CDate(Date())))+4,"m/d/yy")


This can be simplified considerably. For one thing, you don't need to
use CDate() to convert Date() to a date - it already IS a date. For
another, you can use the optional third argument of Weekday. To get a
*text string* (which is not a date and is not a range, it's just a
human readable string) try

DateAdd("d", -WeekDay(Date(), vbThursday), Date()) & "-" &
DateAdd("d", 8-WeekDay(Date(), vbThursday), Date())

You might need to wrap the DateAdd() calls in Format.

To validate the WorkDate control, try code like this in the control's
BeforeUpdate event:

Private Sub WorkDate_BeforeUpdate(Cancel as Intager)
If CDate(Me!WorkDate) DateAdd("d", -Weekday(Date(), vbThursday), _
Date()) OR _
CDate(Me!WorkDate) DateAdd("d", 8-Weekday(Date(), vbThursday), _
Date()) Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If
End Sub

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps

  #3  
Old October 27th, 2004, 03:30 AM
Dave Elliott
external usenet poster
 
Posts: n/a
Default

The data in the WorkDate is a date in m/d/yy format with a default of
Date()
Example; The current work week is 10/21/04 thru 10/27/04
Any date outside these parameters should not work.

"John Vinson" wrote in message
...
On Tue, 26 Oct 2004 18:15:20 GMT, "Dave Elliott"
wrote:

I have a form where I enter an employees payroll time with the date
criteria
for there payroll week.
The payroll week runs Thursday Thru Wednesday. See Code Below. On the
form
there is a control
named WorkDate with it's control set to Work Date and this is the date
between the beginning and ending date
that calculates when they get paid, i.e. if there time is entered between
the two dates, they will get paid.


I'm confused. Is the data in WorkDate a date value, or a number of
days, or what?

The Text Box where this code below is located is named Text999
If the date entered is not between these two dates, (Work Date control)
or
name WorkDate
I need a message box to appear telling me so.
How can I do this?



=Format(CDate(Date())-(Weekday(CDate(Date())))-2,"m/d/yy") & "-" &
Format(CDate(Date())-(Weekday(CDate(Date())))+4,"m/d/yy")


This can be simplified considerably. For one thing, you don't need to
use CDate() to convert Date() to a date - it already IS a date. For
another, you can use the optional third argument of Weekday. To get a
*text string* (which is not a date and is not a range, it's just a
human readable string) try

DateAdd("d", -WeekDay(Date(), vbThursday), Date()) & "-" &
DateAdd("d", 8-WeekDay(Date(), vbThursday), Date())

You might need to wrap the DateAdd() calls in Format.

To validate the WorkDate control, try code like this in the control's
BeforeUpdate event:

Private Sub WorkDate_BeforeUpdate(Cancel as Intager)
If CDate(Me!WorkDate) DateAdd("d", -Weekday(Date(), vbThursday), _
Date()) OR _
CDate(Me!WorkDate) DateAdd("d", 8-Weekday(Date(), vbThursday), _
Date()) Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If
End Sub

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps



  #4  
Old October 27th, 2004, 04:05 AM
Dave Elliott
external usenet poster
 
Posts: n/a
Default

I created (2) text boxes that may help explain what I am trying to do.
one is named Text104 which shows the week starting
date:=Format(CDate(Date())-(Weekday(CDate(Date())))-2,"m/d/yy")
the other is named Text106 which shows the week end
date:=Format(CDate(Date())-(Weekday(CDate(Date())))+4,"m/d/yy")
I then tried this code in the beforeupdate event of WorkDate;
Of course it didnt work. But this is what I am after.

If ([Text104]) Date Or ([Text106]) Date Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If



"John Vinson" wrote in message
...
On Tue, 26 Oct 2004 18:15:20 GMT, "Dave Elliott"
wrote:

I have a form where I enter an employees payroll time with the date
criteria
for there payroll week.
The payroll week runs Thursday Thru Wednesday. See Code Below. On the
form
there is a control
named WorkDate with it's control set to Work Date and this is the date
between the beginning and ending date
that calculates when they get paid, i.e. if there time is entered between
the two dates, they will get paid.


I'm confused. Is the data in WorkDate a date value, or a number of
days, or what?

The Text Box where this code below is located is named Text999
If the date entered is not between these two dates, (Work Date control)
or
name WorkDate
I need a message box to appear telling me so.
How can I do this?



=Format(CDate(Date())-(Weekday(CDate(Date())))-2,"m/d/yy") & "-" &
Format(CDate(Date())-(Weekday(CDate(Date())))+4,"m/d/yy")


This can be simplified considerably. For one thing, you don't need to
use CDate() to convert Date() to a date - it already IS a date. For
another, you can use the optional third argument of Weekday. To get a
*text string* (which is not a date and is not a range, it's just a
human readable string) try

DateAdd("d", -WeekDay(Date(), vbThursday), Date()) & "-" &
DateAdd("d", 8-WeekDay(Date(), vbThursday), Date())

You might need to wrap the DateAdd() calls in Format.

To validate the WorkDate control, try code like this in the control's
BeforeUpdate event:

Private Sub WorkDate_BeforeUpdate(Cancel as Intager)
If CDate(Me!WorkDate) DateAdd("d", -Weekday(Date(), vbThursday), _
Date()) OR _
CDate(Me!WorkDate) DateAdd("d", 8-Weekday(Date(), vbThursday), _
Date()) Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If
End Sub

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps



  #5  
Old October 27th, 2004, 04:35 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Wed, 27 Oct 2004 03:05:11 GMT, "Dave Elliott"
wrote:

I created (2) text boxes that may help explain what I am trying to do.
one is named Text104 which shows the week starting


Dave, did you try what I suggested?

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
  #6  
Old October 27th, 2004, 01:30 PM
Dave Elliott
external usenet poster
 
Posts: n/a
Default

Yes, it wouldnt let me put in the DateAdd() for the date and so code did not
work. To be sure I understand, I tried this

If CDate(Me!WorkDate) DateAdd()("d", -Weekday(Date(), vbThursday), _
Date()) OR _
CDate(Me!WorkDate) DateAdd()("d", 8-Weekday(Date(), vbThursday), _
Date()) Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If


"John Vinson" wrote in message
news
On Wed, 27 Oct 2004 03:05:11 GMT, "Dave Elliott"
wrote:

I created (2) text boxes that may help explain what I am trying to do.
one is named Text104 which shows the week starting


Dave, did you try what I suggested?

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps



  #7  
Old October 27th, 2004, 05:41 PM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Wed, 27 Oct 2004 12:30:57 GMT, "Dave Elliott"
wrote:

Yes, it wouldnt let me put in the DateAdd() for the date and so code did not
work. To be sure I understand, I tried this

If CDate(Me!WorkDate) DateAdd()("d", -Weekday(Date(), vbThursday), _
Date()) OR _
CDate(Me!WorkDate) DateAdd()("d", 8-Weekday(Date(), vbThursday), _
Date()) Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If


That's not what I posted. You're putting in DateAdd() - which will
fail, because you're passing it zero arguments and DateAdd needs
three; and then you have the arguments in parentheses afterwards.

Try

If CDate(Me!WorkDate) DateAdd("d", -Weekday(Date(), vbThursday), _
Date()) OR _
CDate(Me!WorkDate) DateAdd("d", 8-Weekday(Date(), vbThursday), _
Date()) Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If


John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
  #8  
Old October 27th, 2004, 06:43 PM
Dave Elliott
external usenet poster
 
Posts: n/a
Default

John, tried your code, but nothing happened, I could enter a future date or
a past date outside the present date week with no problems.
Any More Suggestions?

"John Vinson" wrote in message
...
On Wed, 27 Oct 2004 12:30:57 GMT, "Dave Elliott"
wrote:

Yes, it wouldnt let me put in the DateAdd() for the date and so code did
not
work. To be sure I understand, I tried this

If CDate(Me!WorkDate) DateAdd()("d", -Weekday(Date(), vbThursday), _
Date()) OR _
CDate(Me!WorkDate) DateAdd()("d", 8-Weekday(Date(), vbThursday), _
Date()) Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If


That's not what I posted. You're putting in DateAdd() - which will
fail, because you're passing it zero arguments and DateAdd needs
three; and then you have the arguments in parentheses afterwards.

Try

If CDate(Me!WorkDate) DateAdd("d", -Weekday(Date(), vbThursday), _
Date()) OR _
CDate(Me!WorkDate) DateAdd("d", 8-Weekday(Date(), vbThursday), _
Date()) Then
Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If


John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps



  #9  
Old October 28th, 2004, 05:58 PM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Wed, 27 Oct 2004 17:43:20 GMT, "Dave Elliott"
wrote:

John, tried your code, but nothing happened, I could enter a future date or
a past date outside the present date week with no problems.
Any More Suggestions?


Please post your actual code. Other than using the debugger to step
through the code line by line, checking the values of the various
dates, I don't know what else to suggest!

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
  #10  
Old October 28th, 2004, 07:00 PM
Dave Elliott
external usenet poster
 
Posts: n/a
Default

The database is quite complicated, The code below should check for dates
between
(CDate(Date())-(Weekday(CDate(Date())))-2,"m/d/yy") 'This weeks Thursday
(CDate(Date())-(Weekday(CDate(Date())))+4,"m/d/yy") 'This weeks Wednesday
Anyway, I thank you for your help. Actual code is below.

If CDate(Me!WorkDate) DateAdd("d", -Weekday(Date, vbThursday), Date) _
Or CDate(Me! _
WorkDate) DateAdd("d", 8 - Weekday(Date, vbThursday), Date) Then _

Cancel = True
MsgBox "Enter a date within the work week", vbOKOnly
End If

"John Vinson" wrote in message
...
On Wed, 27 Oct 2004 17:43:20 GMT, "Dave Elliott"
wrote:

John, tried your code, but nothing happened, I could enter a future date
or
a past date outside the present date week with no problems.
Any More Suggestions?


Please post your actual code. Other than using the debugger to step
through the code line by line, checking the values of the various
dates, I don't know what else to suggest!

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
QDE (Quick Date Entry) Norman Harker General Discussion 3 September 3rd, 2004 08:00 AM
Formatting dates in Excel bernrunner15 New Users 4 May 11th, 2004 10:32 PM
Problem with date format Colin Worksheet Functions 9 January 29th, 2004 03:05 AM
Does date fall between two ranges? MR Worksheet Functions 4 January 14th, 2004 04:08 PM


All times are GMT +1. The time now is 10:40 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.