why my BeforeUpdate does not work?

S

Song Su

I intentionally tried both conditions but MsgBox does not start. Where did I
do wrong?

Private Sub cboFrom_BeforeUpdate(Cancel As Integer)
If Me.From < DMin("TimeIn", "qryVisitData") Then
MsgBox ("FROM cannot be earlier than downloaded data range")
Cancel = True
End If
If Me.From > Me.To Then
MsgBox ("FROM must be same or earler than TO")
Cancel = True
End If

End Sub
 
A

AccessVandal via AccessMonster.com

Hi Song Su,

Is your combobox named "Me.From" or "Me.cboFrom".
Judging from the event name, it's unlikely to be "From" but
rather "cboFrom".
 
J

John W. Vinson

I intentionally tried both conditions but MsgBox does not start. Where did I
do wrong?

Private Sub cboFrom_BeforeUpdate(Cancel As Integer)
If Me.From < DMin("TimeIn", "qryVisitData") Then
MsgBox ("FROM cannot be earlier than downloaded data range")
Cancel = True
End If
If Me.From > Me.To Then
MsgBox ("FROM must be same or earler than TO")
Cancel = True
End If

End Sub

The DMin() call will return the earliest value of TimeIn in the entire query
qryVisitData. Not being able to see qryVisitData, it's not obvious to me that
it's getting the record you want - does qryVisitData contain only records
pertinant to this form?

The other possibility is that you haven't specified the datatype. It may be
treating Me.from as a Text string. Try

If CDate(Me![From]) < DMin("[TimeIn]", "[qryVisitData]") Then

and

If CDate(Me![From]) > CDate(Me![To]) Then


John W. Vinson [MVP]
 
Top