Connecting Tech Pros Worldwide Help | Site Map

Best practices for canceling out of a report?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 02:04 PM
Denise
Guest
 
Posts: n/a
Default 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


  #2  
Old November 13th, 2005, 02:04 PM
PC Datasheet
Guest
 
Posts: n/a
Default Re: Best practices for canceling out of a report?

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
resource@pcdatasheet.com
www.pcdatasheet.com



"Denise" <dh98765@gmail.com> wrote in message
news:1128358750.630596.194750@g43g2000cwa.googlegr oups.com...[color=blue]
> 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
>[/color]


  #3  
Old November 13th, 2005, 02:04 PM
Denise
Guest
 
Posts: n/a
Default Re: Best practices for canceling out of a report?

Yes, that worked perfectly!

Thanks for the quick response.

Denise

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.