On Click event date parameter

  • Thread starter Thread starter Tony Williams
  • Start date Start date
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
 
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
 
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
 

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