Only allow date entry for current month

JFHBIFF

Registered User.
Local time
Yesterday, 20:38
Joined
Jan 8, 2006
Messages
14
Hello,

I am a little familiar with Access but having a problem figuring out how to alert a user that the date entered on a form is not the current month. I was hoping to have a warning msgbox pop up alerting the user. I am trying to prevent incorrect date entry.

Thank you very much
 
On the AfterUpdate event of the date input control, test the date toi make sure it's within the current month, e.g.

private sub txtDate_AfterUpdate()
If Me!txtDate & "" = "" Then Exit Sub
If Month(Me!txtDate) <> Month(Date) Then
MsgBox "Error"
End If
End Sub

Be carefull of Null or empty dates. What about invalid year? In the latter case make a similar use of the Year function.
 
Thank you very much for your help llkhoutx. Works perfectly, now that you got me thinking about incorrect year I tried the code shown below. Problem with my code is, if the month is correct and the year isn't it wont pick up the incorrect year. Is there a way to combine the two so both work?

I am pretty new at this

Thanks,


private sub txtDate_AfterUpdate()


If Me!txtDate & "" = "" Then Exit Sub
If Month(Me!txtDate) <> Month(Date) Then
MsgBox "Make sure the month entered is correct"

If Me!txtDate & "" = "" Then Exit Sub
If Year(Me!txtDate) <> Year(Date) Then
MsgBox "Make sure the year entered is correct"


End If
End If



End Sub
 
Ok, I figured it out. I had the end if in the wrong place.

Thanks for your help
 

Users who are viewing this thread

Back
Top Bottom