469,647 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

Best practices for canceling out of a report?

How do I get the report to not spend time pulling up the data when I'm
going to bail out of the report anyway?

Below is the code in my report. I first show the user a form where
they can select some filtering parameters which I put in Getz's
TaggedValues class. But they can hit a Cancel button if they decide
they don't want any report. When I test the Cancel button I'd like the
report to close immediately but it seems to spend some time pulling up
data first.

(I've tried to put docmd.Close in the Report_Open but that closes the
whole database so I've been putting it in the Report_Activate.)

The Record Source is a query and the report has no fields that are
calculated, all fields are straight from the query.

Any advice?
THANKS!

----- Here is the code...

Option Compare Database
Option Explicit
Public CloseNow As String ' I know boolean would be better

Private Sub Report_Open(Cancel As Integer)
Dim strMyFilter As String
Dim tv As TaggedValues

CloseNow = "No" ' Public string

' This form sets TaggedValues in both OK and Close
' buttons, then sets its Visibile = false
DoCmd.OpenForm "frmSelectOpCheckVars", , , , , acDialog

Set tv = New TaggedValues
tv.Text = Forms!frmSelectOpCheckVars!txtMyTags.Tag
' Close the selection form
DoCmd.Close acForm, "frmSelectOpCheckVars"

If tv.Item("Canceled") = "Yes" Then
MsgBox "Click OK to close. This may take a few seconds... ", ,
"REPORT CLOSING"
CloseNow = "Yes"
Else
' set strMyFilter here...
Me.Filter = strMyFilter
Me.FilterOn = True
End If ' end of If canceled = yes

Set tv = Nothing

End Sub

Private Sub Report_Activate()
If CloseNow = "Yes" Then
DoCmd.Close
End If
End Sub

Nov 13 '05 #1
2 1435
Start with the following code somewhere:
DoCmd.openReport ......
On Error Resume Next
The On Error code is necessary because Access will raise an error when you
cancel the report.

Put your code to open your form where users can select some filtering
parameters in the Report's Open event. The code would look like:
DoCmd.OpenForm "MyParameterForm",,,,,acDialog
If IsLoaded("MyParameterForm") = False Then
Cancel = True
End If
(You can find the code for the IsLoaded function in NorthWind's standard
modules.)

You will need a button on the form to Continue after the users select the
parameters. The Continue button code would be:
Me.Visible = False

Put the following code in the Cancel button's Click event:
DoCmd.Close acForm, "MyParameterForm"

Put the following code in the Report's Close event:
DoCmd.Close acForm, "MyParameterForm"

The form doesn't load unless you select parameters and Click the Continue
button so it won't prematurely pull up any data.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com

"Denise" <dh*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
How do I get the report to not spend time pulling up the data when I'm
going to bail out of the report anyway?

Below is the code in my report. I first show the user a form where
they can select some filtering parameters which I put in Getz's
TaggedValues class. But they can hit a Cancel button if they decide
they don't want any report. When I test the Cancel button I'd like the
report to close immediately but it seems to spend some time pulling up
data first.

(I've tried to put docmd.Close in the Report_Open but that closes the
whole database so I've been putting it in the Report_Activate.)

The Record Source is a query and the report has no fields that are
calculated, all fields are straight from the query.

Any advice?
THANKS!

----- Here is the code...

Option Compare Database
Option Explicit
Public CloseNow As String ' I know boolean would be better

Private Sub Report_Open(Cancel As Integer)
Dim strMyFilter As String
Dim tv As TaggedValues

CloseNow = "No" ' Public string

' This form sets TaggedValues in both OK and Close
' buttons, then sets its Visibile = false
DoCmd.OpenForm "frmSelectOpCheckVars", , , , , acDialog

Set tv = New TaggedValues
tv.Text = Forms!frmSelectOpCheckVars!txtMyTags.Tag
' Close the selection form
DoCmd.Close acForm, "frmSelectOpCheckVars"

If tv.Item("Canceled") = "Yes" Then
MsgBox "Click OK to close. This may take a few seconds... ", ,
"REPORT CLOSING"
CloseNow = "Yes"
Else
' set strMyFilter here...
Me.Filter = strMyFilter
Me.FilterOn = True
End If ' end of If canceled = yes

Set tv = Nothing

End Sub

Private Sub Report_Activate()
If CloseNow = "Yes" Then
DoCmd.Close
End If
End Sub

Nov 13 '05 #2
Yes, that worked perfectly!

Thanks for the quick response.

Denise

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Aadam | last post: by
136 posts views Thread by Matt Kruse | last post: by
13 posts views Thread by john doe | last post: by
4 posts views Thread by Luis Esteban Valencia | last post: by
10 posts views Thread by jojobar | last post: by
reply views Thread by Louis Aslett | last post: by
1 post views Thread by Pablo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.