**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: - Private Sub CmdRunRpt_Click()
-
If ReportFrame = 1 Then DoCmd.OpenReport "Rpt 1", acViewPreview
-
If ReportFrame = 2 Then DoCmd.OpenReport "Rpt 2", acViewPreview
-
If ReportFrame = 3 Then DoCmd.OpenReport "Rpt 3", acViewPreview
-
If ReportFrame = 4 Then DoCmd.OpenReport "Rpt 4", acViewPreview
-
If ReportFrame = 5 Then DoCmd.OpenReport "Rpt 5", acViewPreview
-
If ReportFrame = 6 Then DoCmd.OpenReport "Rpt 6", acViewPreview
-
If ReportFrame = 7 Then DoCmd.OpenReport "Rpt 7", acViewPreview
-
If ReportFrame = 8 Then DoCmd.OpenReport "Rpt 8", acViewPreview
-
If ReportFrame = 9 Then DoCmd.OpenReport "Rpt 9", acViewPreview
-
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: - Run-time error '2501':
-
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
6 2878
What's your code for cancelling the report?
Linq ;0)>
Here's the code for the click event of the cancel button on the form: -
Private Sub Cancel_Click()
-
'Purpose: Clear all the search boxes in the Form Detail and close the form.
-
Dim ctl As Control
-
'Clear all the controls in the Form Detail section.
-
For Each ctl In Me.Section(acDetail).Controls
-
Select Case ctl.ControlType
-
Case acTextBox, acComboBox
-
ctl.Value = Null
-
Case acCheckBox
-
ctl.Value = False
-
End Select
-
Next
-
'Remove the form's filter.
-
Me.FilterOn = False
-
'Close the form.
-
DoCmd.close
-
End Sub
Here is the code on the report: - Option Compare Database
-
-
Private Sub Report_Close()
-
DoCmd.close acForm, "Search Start Detail"
-
End Sub
-
-
Private Sub Report_Open(Cancel As Integer)
-
' Set public variable to true to indicate that the report
-
' is in the Open event
-
bInReportOpenEvent = True
-
-
' Open Search Start Detail Dialog
-
DoCmd.OpenForm "Search Start Detail", , , , , acDialog
-
-
' Cancel Report if User Clicked the Cancel Button
-
If IsLoaded("Search Start Detail") = False Then Cancel = True
-
-
' Set public variable to false to indicate that the
-
' Open event is completed
-
bInReportOpenEvent = False
-
End Sub
And here is the supporting module for the report code: - Option Compare Database
-
Option Explicit
-
Public bInReportOpenEvent As Boolean ' Is report in the Open event?
-
-
Function IsLoaded(ByVal strFormName As String) As Boolean
-
' Returns True if the specified form is open in Form view or
-
' Datasheet view.
-
Dim oAccessObject As AccessObject
-
Set oAccessObject = CurrentProject.AllForms(strFormName)
-
If oAccessObject.IsLoaded Then
-
If oAccessObject.CurrentView <> acCurViewDesign Then
-
IsLoaded = True
-
End If
-
End If
-
End Function
Hope that helps - thanks!
martin
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)>
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): -
Private Sub CmdRunRpt_Click()
-
If ReportFrame = 1 Then DoCmd.OpenReport "Rpt 1", acViewPreview
-
If ReportFrame = 2 Then DoCmd.OpenReport "Rpt 2", acViewPreview
-
If ReportFrame = 3 Then DoCmd.OpenReport "Rpt 3", acViewPreview
-
If ReportFrame = 4 Then DoCmd.OpenReport "Rpt 4", acViewPreview
-
If ReportFrame = 5 Then DoCmd.OpenReport "Rpt 5", acViewPreview
-
If ReportFrame = 6 Then DoCmd.OpenReport "Rpt 6", acViewPreview
-
If ReportFrame = 7 Then DoCmd.OpenReport "Rpt 7", acViewPreview
-
If ReportFrame = 8 Then DoCmd.OpenReport "Rpt 8", acViewPreview
-
If ReportFrame = 9 Then DoCmd.OpenReport "Rpt 9", acViewPreview
-
End Sub
So try turning the warnings on and off at this point.
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
| |