Not DatePart

C

Captain OhNo

Hello,
I want to limit the date User's can input into a field to be a Friday.

I have the following code in the BeforeUpdate Event of the Date Field

If (Not (DatePart ("d", [DateField]))=6) Then
MsgBox ("Please Enter Friday's Date")
End If

I have changed the parenthesis around (among other trials and errors) but my
results are always the same. No matter which date I put into the DateField,
I get the Message "Please Enter Friday's Date".

Can you assist me with what I am doing wrong?
Thank you
Captain OhNo
 
A

AccessExpert

the d gives you the day of month. Use w for day of week.

If Not (DatePart("w", [Text0]) = 6) Then
MsgBox ("Please Enter Friday's Date")
End If
 
C

Captain OhNo

It worked. So, now you know how I got my nickname...
Captain OhNo
Thank you

AccessExpert said:
the d gives you the day of month. Use w for day of week.

If Not (DatePart("w", [Text0]) = 6) Then
MsgBox ("Please Enter Friday's Date")
End If


Captain OhNo said:
Hello,
I want to limit the date User's can input into a field to be a Friday.

I have the following code in the BeforeUpdate Event of the Date Field

If (Not (DatePart ("d", [DateField]))=6) Then
MsgBox ("Please Enter Friday's Date")
End If

I have changed the parenthesis around (among other trials and errors) but my
results are always the same. No matter which date I put into the DateField,
I get the Message "Please Enter Friday's Date".

Can you assist me with what I am doing wrong?
Thank you
Captain OhNo
 
V

Van T. Dinh

"d" returns day of the month. You actually want "w" which returns weekday.

Check Access VB Help for the argument "firstdayofweek" also.
 
Top