date controls

A

Alan

Hello,

I have a date field ona form that I'm trying to prevent the user from
entering dates in the past.

On the AfterUpdate event I wrote the following code as a warning message if
they pick a date older than current:

Private Sub pkgShip_AfterUpdate()

If Me.pkgShip < Now() Then
MsgBox ("You cannot select a date in the past. Please select another
date.")
Else
End If

End Sub

However nothing seems to happen if I enter dates in the past. Is this not
the way to do it or am I writing this statement incorrectly?

Thanks.

Al
 
K

Ken Snell \(MVP\)

Use the BeforeUpdate event of the control:

Private Sub pkgShip_BeforeUpdate(Cancel As Integer)

If DateValue(Me.pkgShip) < Date() Then
MsgBox "You cannot select a date in the past. Please select another
date.", vbExclamation, "Old Date!"
Cancel = True
End If

End Sub
 
A

Alan

That worked great!

Thanks!

Al

Ken Snell (MVP) said:
Use the BeforeUpdate event of the control:

Private Sub pkgShip_BeforeUpdate(Cancel As Integer)

If DateValue(Me.pkgShip) < Date() Then
MsgBox "You cannot select a date in the past. Please select another
date.", vbExclamation, "Old Date!"
Cancel = True
End If

End Sub
 
Top