Solved

Access 2007 - Cancelling openreport from VBA code

Posted on 2009-05-04
2
651 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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