Hey Rich (e.g. Form date guru!) (1 Viewer)

MikeG

Registered User.
Local time
Today, 06:39
Joined
Oct 1, 2001
Messages
31
To ensure that each date field (3) on my form is not entered earlier than the previous one shown, I attempted to setup a before update event based upon what I've found in searching on date verification or date validation in the forum.

Note - I defined BadDate in the OptionExplicit...

Private Sub Date2_BeforeUpdate(Cancel As Integer)
If Me!Date2 < Me!Date1 Then
BadDate = MsgBox("Date2 is earlier than Date1, please correct!", vbOKOnly + vbInformation, "Wrong date selected!")
Date2.SetFocus
End If
End Sub

I am using one calendar control to load all 3 dates on the form (via a variable). I want to also check to ensure that Date #3 is later than Date #2 but... the first check isn't working at all. I suspect the calendar control is the culprit.

Thoughts?

MikeG
 

MarkK

bit cruncher
Local time
Yesterday, 22:39
Joined
Mar 17, 2004
Messages
8,198
Private Sub Date2_BeforeUpdate(Cancel As Integer)
If Me.Date2 < Me.Date1 Then
MsgBox("Date2 is earlier than Date1, please correct!", vbOKOnly + vbInformation, "Wrong date selected!")
Date2.SetFocus
Cancel = True
End If
End Sub
 

MikeG

Registered User.
Local time
Today, 06:39
Joined
Oct 1, 2001
Messages
31
Thanks, Lagbolt. Unfortunately, that didn't work. I'm still trying!
I'll add that this is the coding I'm using for the calendar selection.

Private Sub Date2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboVariablebox = Date2
ocxCalendar.Visible = True
ocxCalendar.SetFocus
If Not IsNull(cboVariablebox) Then
ocxCalendar.Value = Date2.Value
Else
ocxCalendar.Value = Date
End If
End Sub

and this is for selecting the date from the calendar then hiding it again:

Private Sub ocxCalendar_Click()
cboVariablebox = ocxCalendar.Value
cboVariablebox.SetFocus
ocxCalendar.Visible = False
Set cboVariablebox = Nothing
End Sub

The variable cboVariableBox is defined as a combobox first and allows multiple calendar selections.

As I said before, I'm still playing with it but I'm about to put it away for the day. Thanks!


m
 

Users who are viewing this thread

Top Bottom