Date Validation/End of Month

LaurieW

Registered User.
Local time
Today, 18:47
Joined
May 9, 2002
Messages
99
I need to check a date field to be sure the user enters an end-of-month date (e.g., 1/31, 2/28, etc.) I've started writing the code, but keep getting an error about saving the field. I don't want to save the field. What I want to have happen is: if the date is not an end-of-month date, show a message box and return the cursor to the date field ... what am I missing (something simple, I'm sure)...here's what I have so far:

Private Sub StatusDate_BeforeUpdate(Cancel As Integer)
If Month(StatusDate) = 1 And Day(StatusDate) <> 31 Then
MsgBox "Date must be end of month", vbExclamation
StatusDate.SetFocus
Cancel = True
End If
End Sub
 
Never mind!

I figured this out...never mind. Here's what I've got that works just fine:

Private Sub StatusDate_BeforeUpdate(Cancel As Integer)
If Month(StatusDate) = 1 And Day(StatusDate) <> 31 Then
MsgBox "Date must be end of month", vbExclamation
Cancel = True
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom