Solved

Access 2007 - Cancelling openreport from VBA code

Posted on 2009-05-04
2
649 Views
Last Modified: 2013-11-28
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

0
Comment
Question by:jeffkwells2003
2 Comments
 
LVL 46

Expert Comment

by:tbsgadi
ID: 24293953
You need to add error handling to the routine that opens the report

Gary
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 24293960
You can simply "catch" the error:

On Error GoTo Err_Hand

cancelrep = False
DoCmd.OpenForm "ChooseRepMonthYear", , , , , acDialog
 If cancelrep Then
   Cancel = True
   Exit Sub
End If

Err_Hand:
  If Err.Number = 2501 Then
    Exit sub
  Else
    '/do something else here
  End If
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now