why my BeforeUpdate does not work?

  • Thread starter Thread starter Song Su
  • Start date Start date
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
 
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".
 
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]
 

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

Back
Top