Allan Browne Calendar question

D

deb

I am using Allan Browne's calendar and it works great!!
I have a form with ProjStart and ProjEnd, both are date fields using the
calendar.

I need to make sure the ProjEnd is not before ProjStart.
I tried...
Private Sub ProjStart_AfterUpdate()
If Me.ProjStart> Me.ProjEnd Then
MsgBox "ProjEnd cannot be before ProjStart"
Me.ProjStart.Undo
End If
End Sub
But it only works if the date is typed in, and not when using the calendar
control.

The calendar is triggered by the OnClick event using,
=CalendarFor([ProjStart],"Set Project Start date")

Please help,
 
A

Allen Browne

Assuming this is a bound form, use the BeforeUpdate event procedure of the
*form* to verify that the end date is after the start date. That's always
the best approach for comparing 2 dates, becuase you don't know which order
the user will enter them.

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me.ProjEnd < Me.ProjStart Then
Cancel = True
MsgBox "Cannot end before it starts."
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top