Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Howto: open a report like a dialog box 1

Status
Not open for further replies.

psemianonymous

Programmer
Dec 2, 2002
1,877
US
I found this extremely useful piece of VBA code. It will loop until the report closes--this means that you can run some code, open the report, wait until the report is closed, and then continue with the code. This was useful for me as I confirm using a messagebox that the report prints correctly. Anyway, there's just three steps:

1. Open your report in preview mode.
2. Select your report (set the focus to your report). This step is optional, though it is usually implied.
3. Run a "DoEvents Loop" until the report disappears. If you don't put "DoEvents" inside the loop, your program will totally freeze.


Here is how I used it:
Code:
    If rptFilter = "" Then
        DoCmd.OpenReport "rptDUNNING_LETTER_RFI", acViewPreview
    Else
        DoCmd.OpenReport "rptDUNNING_LETTER_RFI", acViewPreview, , rptFilter
    End If
    
    DoCmd.SelectObject acReport, "rptDUNNING_LETTER_RFI"
    Do While SysCmd(acSysCmdGetObjectState, acReport, "rptDUNNING_LETTER_RFI") = 1
        DoEvents
    Loop
    
    'In a different function I run the message box.  Not
    'in this one.


(found it here: --
Find common answers using Google Groups:

 
Cool-

You can also do this:

While currentproject.allreports("rptDUNNING_LETTER_RFI").isloaded
DoEvents
wend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top