By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

Canceling an input form

P: n/a
Quick question for you. I'm using a small form for users to input a range of
dates for a report (similar to the date range forms used in MS templates)
that has an ok and a cancel button. How can I set up the cancel button so
that is does just that? As it is right now, the event for the cancel button
is simply docmd.close but if I click this button, ms prompts me to enter
parameter values for begindate and enddate. If i cancel out of these
prompts, i get an error - "The OpenReport action was canceled" and if I
enter something or click ok to the prompts, the report opens with no data
for obvious reasons. How can I kill the whole process with the cancel
button?
Dec 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Thu, 21 Dec 2006 03:00:06 GMT, Jimmy wrote:
Quick question for you. I'm using a small form for users to input a range of
dates for a report (similar to the date range forms used in MS templates)
that has an ok and a cancel button. How can I set up the cancel button so
that is does just that? As it is right now, the event for the cancel button
is simply docmd.close but if I click this button, ms prompts me to enter
parameter values for begindate and enddate. If i cancel out of these
prompts, i get an error - "The OpenReport action was canceled" and if I
enter something or click ok to the prompts, the report opens with no data
for obvious reasons. How can I kill the whole process with the cancel
button?
That error, Error 2501, is a common error caused when a report
opening is canceled.

Trap the error in whatever code event is used to open the report, i.e.

Private Sub Command12_Click()
On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName" ,acViewPreview

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error " & Err.Number & ' " & Err.Description
End If
Resume Exit_Sub
End Sub
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Dec 21 '06 #2

P: n/a

Jimmy wrote:
Quick question for you. I'm using a small form for users to input a range of
dates for a report (similar to the date range forms used in MS templates)
that has an ok and a cancel button. How can I set up the cancel button so
that is does just that? As it is right now, the event for the cancel button
is simply docmd.close but if I click this button, ms prompts me to enter
parameter values for begindate and enddate. If i cancel out of these
prompts, i get an error - "The OpenReport action was canceled" and if I
enter something or click ok to the prompts, the report opens with no data
for obvious reasons. How can I kill the whole process with the cancel
button?
Sounds like there's something here you're not telling. Did you base
your report on a parameter query? Don't. Pass filters in the Open
event of your report. Then if you cancel, nothing should happen. Your
button should have maybe one event

DoCmd.OpenReport "ReportName",.... <somewhere out here is the filter -
just a valid WHERE clause without the WHERE keyword>.

If you don't try to open the report, then you won't get any errors,
just no open report. So I guess it might help if you posted your code.

Pieter

Dec 21 '06 #3

P: n/a

<pi********@hotmail.comwrote in message
news:11**********************@t46g2000cwa.googlegr oups.com...
>
Sounds like there's something here you're not telling. Did you base
your report on a parameter query? Don't. Pass filters in the Open
event of your report. Then if you cancel, nothing should happen. Your
button should have maybe one event
Yes, the form/report is based on those used in many of MS templates. When
the user opens a report the onopen event opens a form frmDateRange where the
user inputs a beginning and ending date, clicks ok and then the report opens
and uses the two values from the date range form in the reports query to
limit the data displayed. What I am looking for is a way for the user to
cancel the date range form and have that form close and essentially the
report close (since I believe it is technically open already since the
calling of frmDateRange is in the reports onopen event).
>
DoCmd.OpenReport "ReportName",.... <somewhere out here is the filter -
just a valid WHERE clause without the WHERE keyword>.

If you don't try to open the report, then you won't get any errors,
just no open report. So I guess it might help if you posted your code.
Report's OnOpen event:
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmReportDateRange", , , , , acDialog
End Sub

Form frmDateRange onClick event for OK Button:
Private Sub cmdOK_Click()
If IsNull([BeginDate]) Or IsNull([EndDate]) Then
MsgBox "You must enter both beginning and ending dates."
DoCmd.GoToControl "BeginDate"
Else
If [BeginDate] [EndDate] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "BeginDate"
Else
Me.Visible = False
End If
End If
End Sub

After clicking the OK button, the date range form becomes not visible and
the report becomes visible.

>
Pieter

Dec 21 '06 #4

P: n/a
Jimmy wrote:
<pi********@hotmail.comwrote in message
news:11**********************@t46g2000cwa.googlegr oups.com...
>>Sounds like there's something here you're not telling. Did you base
your report on a parameter query? Don't. Pass filters in the Open
event of your report. Then if you cancel, nothing should happen. Your
button should have maybe one event


Yes, the form/report is based on those used in many of MS templates. When
the user opens a report the onopen event opens a form frmDateRange where the
user inputs a beginning and ending date, clicks ok and then the report opens
and uses the two values from the date range form in the reports query to
limit the data displayed. What I am looking for is a way for the user to
cancel the date range form and have that form close and essentially the
report close (since I believe it is technically open already since the
calling of frmDateRange is in the reports onopen event).
>>DoCmd.OpenReport "ReportName",.... <somewhere out here is the filter -
just a valid WHERE clause without the WHERE keyword>.

If you don't try to open the report, then you won't get any errors,
just no open report. So I guess it might help if you posted your code.


Report's OnOpen event:
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmReportDateRange", , , , , acDialog
End Sub

Form frmDateRange onClick event for OK Button:
Private Sub cmdOK_Click()
If IsNull([BeginDate]) Or IsNull([EndDate]) Then
MsgBox "You must enter both beginning and ending dates."
DoCmd.GoToControl "BeginDate"
Else
If [BeginDate] [EndDate] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "BeginDate"
Else
Me.Visible = False
End If
End If
End Sub

After clicking the OK button, the date range form becomes not visible and
the report becomes visible.
Also, don't forget to close "frmReportDateRange" after it closes:

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmReportDateRange", , , , , acDialog
' execution pauses at the line above until form is closed or hidden
' close the hidden form
DoCmd.Close acForm, "frmReportDateRange"
End Sub

--
'---------------
'John Mishefske
'---------------
Dec 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.