Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / July 2007

Tip: Looking for answers? Try searching our database.

Day Validation code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rama - 17 Jul 2007 15:55 GMT
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
missinglinq - 17 Jul 2007 18:47 GMT
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.

Signature

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

Answers/posts based on Access 2000

Douglas J. Steele - 17 Jul 2007 19:05 GMT
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!

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> The WeekDay function returns an Integer representing the Day of the Week
> for
[quoted text clipped - 24 lines]
> This assumes that Sunday (1)  is the FirstDayOf Week. If this is not true,
> substutute the appropriate Integer for the First Day of Week.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.