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 / July 2007

Tip: Looking for answers? Try searching our database.

Validation of date.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jfaz - 17 Jul 2007 09:04 GMT
I have a date field on a form that must only be a sunday date.  I want to
attach a macro that will show a message box if the date entered is not a
Sunday.  I have tried several ways to achieve this but not been sucessful.
Any help would be gratefully appreciated.
Ofer Cohen - 17 Jul 2007 12:00 GMT
In the BeforeUpdate event of the date text box use the following code to
validate the date

If WeekDay(Me.[TextBoxName]) <> 1 Then
  MsgBox "Date must be Sunday"
  Cancel = True  ' will stop the exit from the field
End If

If you just want to display a message, without stoping the process, then
remove
Cancel = True  
from the code

Signature

Good Luck
BS"D

> I have a date field on a form that must only be a sunday date.  I want to
> attach a macro that will show a message box if the date entered is not a
> Sunday.  I have tried several ways to achieve this but not been sucessful.
> Any help would be gratefully appreciated.
Douglas J. Steele - 17 Jul 2007 12:02 GMT
Assuming this is a bound field (named, for the sake of argument,
txtDateField), try something like:

Private Sub txtDateField_BeforeUpdate(Cancel As Integer)

 If IsDate(Me!txtDateField) Then
   If Weekday(Me!txtDateField) <> vbSunday Then
     MsgBox "The date must be a Sunday"
     Cancel = True
   End If
 Else
   MsgBox "You must provide a date"
   Cancel = True
 End If

End Sub

On the other hand, you could simply change the date to the closest Sunday.

Signature

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

>I have a date field on a form that must only be a sunday date.  I want to
> attach a macro that will show a message box if the date entered is not a
> Sunday.  I have tried several ways to achieve this but not been sucessful.
> Any help would be gratefully appreciated.
 
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



©2009 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.