Day Validation code

R

rama

Hello,

I am looking for some help for my data entry form. In the form there
is a combo box, which is used to enter date ("cboLongDate"). The date
format is "Wednesday, June 13, 2007" . I need to confirm the day is
Wednesday or not before the user click on add data or close form. The
important thing is day (ie "Wednesday") not the date as Wednesday
comes every week. If the selected day is not "wednesday" a message box
should pop up saying the day selected is incorrect while closing or
adding data so that user can get a chance to correct it.
Thanks in advance

Rama
 
M

missinglinq via AccessMonster.com

The WeekDay function returns an Integer representing the Day of the Week for
a given date.

Today is Tuesday, July 17, 2007

So WeekDay(Date,1) will return 3 (Tuesday)

So do something like this, probably in the Form BeforeUpdate event:

If WeekDay(Me.cboLongDate, 1) <> 4 Then
Msgbox "Date selected is not a Wednesday!"
'Take whatever corrective action you want here
End If

Integer Values for Weekdays
1 Sun
2 Mon
3 Tue
4 Wed
5 Thu
6 Fri
7 Sat

WeekDay(Me.cboLongDate, 1)

This assumes that Sunday (1) is the FirstDayOf Week. If this is not true,
substutute the appropriate Integer for the First Day of Week.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
D

Douglas J. Steele

It's probably more readable to use the intrinsic constants defined for the
day values (vbSunday, vbMonday, etc.)

In other words,

If WeekDay(Me.cboLongDate, 1) <> vbWednesdau Then
Msgbox "Date selected is not a Wednesday!"
'Take whatever corrective action you want here
End If

is probably a lot more obvious when you go back to read your code weeks
later!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top