On Click event date parameter

T

Tony Williams

I have a date parameter form that has a command button that opens a report.
I have this code on the Onclick button

If [txtto] < [txtfrom] Then
MsgBox "The 'Start Date' is after the 'From date'", vbOKOnly
Cancel = True
End If

If the user clicks on OK I want them to go back to the form. At the moment
the report opens.
What have I done wrong?
Thanks
Tony
 
B

Barry Gilbert

The OnClick event doesn't have a Cancel parameter. Try something like this:

If [txtTo]< [txtFrom] Then
Msgbox "The 'Start Date' is after the 'From date'", vbOKOnly
Else
Docmd.OpenReport "MyReportName"
End If

Barry
 
D

Duncan Bachen

Tony said:
I have a date parameter form that has a command button that opens a report.
I have this code on the Onclick button

If [txtto] < [txtfrom] Then
MsgBox "The 'Start Date' is after the 'From date'", vbOKOnly
Cancel = True
End If

If the user clicks on OK I want them to go back to the form. At the moment
the report opens.
What have I done wrong?
Thanks
Tony

Typically you use the Cancel parameter in the report you are opening.
Defining in it form shouldn't be doing anything. In fact, it should give
you an error if you haven't defined it as a variable.

This isn't all of your code though.

After this if block, you are using code which opens the report. You want
to change your if block to include that code as well.

If [txtto] < [txtfrom] Then
MsgBox "The 'Start Date' is after the 'From date'", vbOKOnly
Else
DoCmd.OpenReport "rptYourReport"
End If
 
Top