Link to home
Start Free TrialLog in
Avatar of jeffkwells2003
jeffkwells2003

asked on

Access 2007 - Cancelling openreport from VBA code

I have a report which is opened from a menu. This report opens a dialog form from the report 'On Open' event to get a date range. On this form I have a 'Cancel' button in case the user changes their mind and this closes the form and sets a flag. This flag is checked by VBA in the report 'on open' event and exits from the report  with the statement 'Cancel=true'. However, this produces the error  2501 "The OpenReport Action was cancelled". I do not get this error if I open the report directly (ie not from my Menu form)
cancelrep = False
DoCmd.OpenForm "ChooseRepMonthYear", , , , , acDialog
 If cancelrep Then
   Cancel = True
   Exit Sub
End If

Open in new window

Avatar of tbsgadi
tbsgadi
Flag of Israel image

You need to add error handling to the routine that opens the report

Gary
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial