Solved

Access 2007 - Cancelling openreport from VBA code

Posted on 2009-05-04
2
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 85

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

734 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