473,883 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URGENT NEED - cancel opening of report via form command button

114 New Member
**Urgent Need**

I'll throw out the basics and any assistance is very, very, very much appreciated!

Access 2003 on XP
On a form (frmMain) is an option group of check boxes (ReportFrame) from which a user can choose a specific report to generate. The user selects the report of choice then presses a comand button (CmdRunRpt). The command button runs using the code below:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdRunRpt_Click()
  2. If ReportFrame = 1 Then DoCmd.OpenReport "Rpt 1", acViewPreview
  3. If ReportFrame = 2 Then DoCmd.OpenReport "Rpt 2", acViewPreview
  4. If ReportFrame = 3 Then DoCmd.OpenReport "Rpt 3", acViewPreview
  5. If ReportFrame = 4 Then DoCmd.OpenReport "Rpt 4", acViewPreview
  6. If ReportFrame = 5 Then DoCmd.OpenReport "Rpt 5", acViewPreview
  7. If ReportFrame = 6 Then DoCmd.OpenReport "Rpt 6", acViewPreview
  8. If ReportFrame = 7 Then DoCmd.OpenReport "Rpt 7", acViewPreview
  9. If ReportFrame = 8 Then DoCmd.OpenReport "Rpt 8", acViewPreview
  10. If ReportFrame = 9 Then DoCmd.OpenReport "Rpt 9", acViewPreview
  11. End Sub
This works perfectly. The report opens by first opening a form (Search Start Detail) that provides criteria for the report, which runs on a query.
On the criteria form (Search Start Detail), there are two command buttons: OK and CANCEL. Selecting OK gives the data to the query and generates the report - this works perfectly.
Here's the issue:
Selecting CANCEL should close the form and cancel the generation of any report (as there is no criteria to generate). When I click CANCEL, the form closes correctly but then there is an error message stating:
Expand|Select|Wrap|Line Numbers
  1. Run-time error '2501':
  2. The OpenReport action was canceled.
I'm sure this is a simple twist of the IF code but I'm not sure. Thank you very much for your help - I need to have this straightened out by Wednesday morning.
martin
Oct 30 '07 #1
6 2919
missinglinq
3,532 Recognized Expert Specialist
What's your code for cancelling the report?

Linq ;0)>
Oct 30 '07 #2
martin DH
114 New Member
Here's the code for the click event of the cancel button on the form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Cancel_Click()
  2.     'Purpose:   Clear all the search boxes in the Form Detail and close the form.
  3.     Dim ctl As Control
  4.     'Clear all the controls in the Form Detail section.
  5.     For Each ctl In Me.Section(acDetail).Controls
  6.         Select Case ctl.ControlType
  7.         Case acTextBox, acComboBox
  8.             ctl.Value = Null
  9.         Case acCheckBox
  10.             ctl.Value = False
  11.         End Select
  12.     Next
  13.     'Remove the form's filter.
  14.     Me.FilterOn = False
  15.     'Close the form.
  16.     DoCmd.close
  17. End Sub
Here is the code on the report:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Report_Close()
  4.   DoCmd.close acForm, "Search Start Detail"
  5. End Sub
  6.  
  7. Private Sub Report_Open(Cancel As Integer)
  8. ' Set public variable to true to indicate that the report
  9. ' is in the Open event
  10.   bInReportOpenEvent = True
  11.  
  12. ' Open Search Start Detail Dialog
  13.   DoCmd.OpenForm "Search Start Detail", , , , , acDialog
  14.  
  15. ' Cancel Report if User Clicked the Cancel Button
  16.   If IsLoaded("Search Start Detail") = False Then Cancel = True
  17.  
  18. ' Set public variable to false to indicate that the
  19. ' Open event is completed
  20.   bInReportOpenEvent = False
  21. End Sub
And here is the supporting module for the report code:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Public bInReportOpenEvent As Boolean ' Is report in the Open event?
  4.  
  5. Function IsLoaded(ByVal strFormName As String) As Boolean
  6. ' Returns True if the specified form is open in Form view or
  7. ' Datasheet view.
  8.   Dim oAccessObject As AccessObject
  9.   Set oAccessObject = CurrentProject.AllForms(strFormName)
  10.   If oAccessObject.IsLoaded Then
  11.     If oAccessObject.CurrentView <> acCurViewDesign Then
  12.       IsLoaded = True
  13.     End If
  14.   End If
  15. End Function
Hope that helps - thanks!
martin
Oct 31 '07 #3
missinglinq
3,532 Recognized Expert Specialist
In the Sub Report_Open() replace the line

If IsLoaded("Searc h Start Detail") = False Then Cancel = True

with the lines

DoCmd.SetWarnin gs False
If IsLoaded("Searc h Start Detail") = False Then Cancel = True
DoCmd.SetWarnin gs True

and see if that surpresses the message.

Linq ;0)>
Oct 31 '07 #4
martin DH
114 New Member
I'm afraid not, Linq. When I click debug it comes back to the code for the main form (where the user selects and runs a report):
Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdRunRpt_Click()
  2. If ReportFrame = 1 Then DoCmd.OpenReport "Rpt 1", acViewPreview
  3. If ReportFrame = 2 Then DoCmd.OpenReport "Rpt 2", acViewPreview
  4. If ReportFrame = 3 Then DoCmd.OpenReport "Rpt 3", acViewPreview
  5. If ReportFrame = 4 Then DoCmd.OpenReport "Rpt 4", acViewPreview
  6. If ReportFrame = 5 Then DoCmd.OpenReport "Rpt 5", acViewPreview
  7. If ReportFrame = 6 Then DoCmd.OpenReport "Rpt 6", acViewPreview
  8. If ReportFrame = 7 Then DoCmd.OpenReport "Rpt 7", acViewPreview
  9. If ReportFrame = 8 Then DoCmd.OpenReport "Rpt 8", acViewPreview
  10. If ReportFrame = 9 Then DoCmd.OpenReport "Rpt 9", acViewPreview
  11. End Sub
Oct 31 '07 #5
missinglinq
3,532 Recognized Expert Specialist
So try turning the warnings on and off at this point.
Oct 31 '07 #6
martin DH
114 New Member
So try turning the warnings on and off at this point.
Same results here: Error 2501. I have tried setting the warnings to false on all three objects involved: the report, the main form (where the vba returns on debug), and the criteria form (where I actually select Cancel).
Any other ideas?
Oct 31 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2940
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server where there is no scripts allowed running (the software is from Opentext called Livelink)- therefore I need javascript to do the tasks listed below: 1. validate the form - this has been completed 2. pop up another window that will go ahead and...
4
1778
by: JC Mugs | last post by:
Problem: Have a data entry form that enters new records that we need to print invoices from when the form is completed. I expect to be able to place a command button on the form and print the invoice, but just can't seem to understand the correct way to pass the value to the report and return to a new form. The form uses tblInvoice as the data source, it has a primary key ID1
1
2167
by: Kevin Nechodom | last post by:
I am trying to use a consolidated filter form, where I pass the desired report I wish to run. I would like to install this form on my custom menu bars, but I can't figure out any way to pass data to the form via the menu. I have looked for a RunCode menu type, where I could use DoCmd. I have tried the form type, but I can't access OpenArgs. Are there any other ideas out there? Thanks,
8
1781
by: Emily Jones | last post by:
Very strange one this. Application written in Access 2000. Runs in 2003 at client's site, 2000 on my development system. FE/BE system. The app's startup form sets a few options, opens the switchboard, then closes. Each of the buttons on the Switchboard opens a form (or report). The Switchboard stays open in the background. One is a 'View Courses' form. This presents a list of educational courses,
7
1792
by: Joe | last post by:
Hi, I’m new to asp.net. I want to create an asp.net page that allows user to edit the data. I have pasted my code below. I am able to display the data in a datagrid. At the bottom of the page there are two buttons “Save Changes” and “Cancel”. When “Save Changes” button is clicked saveRec function is called. But for some reason inside saveRec function the value of the textbox is not visible. The line Label2.Text =...
4
7834
by: martin | last post by:
Hello, Is there a way to make a kind of "cancel" button on a form? Suppose you accidently changed or overwrote some data in a form, then I'd like to leave this form at once and cancel any change made in this form. Hopefully someone has a clue for me. thanks a lot!
2
1508
by: feltra | last post by:
Hi, The following is from my friend, who has some technical problem at present in accessing the web... I am writing for him... Kindly request your inputs ASAP, as he has some kind of deadline tomorrow. .......................................................................................... I am having an issue with MDI form. I have an MDI form and some Child forms. In order to enable for a choice, I am displaying a message box in...
4
1591
by: mforema | last post by:
Hey Everybody, I have a form with a label ("Enter Password"), a textbox (with a password InputMask), and two command buttons ("OK" and "Cancel"). I've successfully written code for the "OK" command button to check the password in the textbox with an OnClick event. It then either opens the authorized form or it doesn't. However, I would also like to set an event for the textbox, so when the user hits the Enter key, the same code is executed...
3
2682
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that report, filtered, from different forms. How do I carry the name of the current form into the
0
9933
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9786
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9568
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7115
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5983
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.