473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

URGENT NEED - cancel opening of report via form command button

114 100+
**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 2878
missinglinq
3,532 Expert 2GB
What's your code for cancelling the report?

Linq ;0)>
Oct 30 '07 #2
martin DH
114 100+
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 Expert 2GB
In the Sub Report_Open() replace the line

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

with the lines

DoCmd.SetWarnings False
If IsLoaded("Search Start Detail") = False Then Cancel = True
DoCmd.SetWarnings True

and see if that surpresses the message.

Linq ;0)>
Oct 31 '07 #4
martin DH
114 100+
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 Expert 2GB
So try turning the warnings on and off at this point.
Oct 31 '07 #6
martin DH
114 100+
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
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...
4
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...
1
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...
8
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...
7
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...
4
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...
2
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...
4
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...
3
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.