How to wait till the Report is printed from a form?

G

Guest

MS Access 2K, Windows XP
====================
Hello,

I have a form with a "Submit" button, that performs the following actions:
1. Emails a report based on the current record.
2. Asks the user if s/he wants to print a copy of the report.
3. Asks the user if s/he would like to submit a new request.

I'm using the following line of code to print the report:
=========================================
DoCmd.OpenReport "Request Report", acViewPreview
=========================================
With this line, I get the option to choose the printer, adjust margins etc.,
but the code doesn't wait for me to print the report, and displays the
report, and goes on to ask me if I want to submit a new request.

I've also tried:
===============================================
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection
===============================================
This code simply prints the report, without giving me the option to change
Printer settings.

What I'd like to happen is:
1. I get the option to choose/change printer, adjust margins etc. and then
print the report.
2. The messagebox that asks me to submit another request waits till I finish
printing.

I've done a lot of googling, and also checked the Help section, but have
been unable to find a solution. Will appreciate it if someone can point me in
the correct direction, or correct my code. Also, I'd rather not use the
DoMenuItem code.

Here's the code for actions 2. and 3.
==========================================================
If (MsgBox("Would you like to print a copy of this request?", vbYesNo) =
vbYes) Then
'DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
'DoCmd.PrintOut acSelection
DoCmd.OpenReport "Request Report", acViewPreview
End If

Dim Msg, Style As String
Msg = "Submit another request?"
Style = vbYesNo

If (MsgBox(Msg, vbYesNo)) = vbYes Then
DoCmd.Close acForm, "frmRequest"
DoCmd.OpenForm "frmRequest"
Else
DoCmd.Close acForm, "frmRequest"
DoCmd.Quit acQuitSaveNone
End If
======================================================

Thanks!

-Amit
 
G

Guest

Make your form a pop-up with the properties for Popup=True and Modal=True
and open in view

When you open the form from code, it should look something like
Docmd.OpenForm "TheForm", , , , ,acDialog
rev
 
A

Andreas

You could use the Close event of the report to initiate the last step.

Regards,
Andreas
 
G

Guest

Hi Rev:

I'm not sure if what you suggested will solve my problem. Opening my form as
Popup and Modal won't give me the PrintPreview window for the Report...
Anyways, I'll try it and see if it works. And, yes, the MVPS Access website
has been on my Bookmarks for more than a year now :)

-Amit
 
G

Guest

OK Amit, breaken out the funks now
'This works, I tested it...
'Put this in any standard module and save module with any name.

Public Sub WaitForReportClose(strTheReport As String)
'wait for report to close then execute the next command(s)
' using DoEvents function
'strTheReport = your report with quotes
Do While SysCmd(acSysCmdGetObjectState, acReport, strTheReport) <> 0
DoEvents
Loop
End Sub

'Put this in your form
cmdRunReport_Click
DoCmd.OpenReport "YourReport", acViewPreview
Beep
MsgBox "Yo! Your report is open... And waits till you close it... "
WaitForReportClose "YourReport"
'Insert the rest of your commands here
MsgBox "I Told you!"
End Sub

Rev
 
G

Guest

Oh... forgot, don't edit the public sub in the standard module
it will accept any report you pass to it.
Rev.
 
G

Guest

OK, last post on this one...
I've been kinda slackin on the Access for a while.
I evem had to quit my cushy job of six years before I got fired.
I really wanted to do something to get into the swing of things...
This is your code "Fixed." It works exactly as you proposed.
Add the unedited Public Sub from my previous post to a module and save.
Then in your form add this code. The button for this example is named
cmdSubmit.
Also, I commented out your Quit command, and didn't test with it.
I'll leave that for you.

You can pay me later :)
Peace, Rev.

Private Sub cmdSubmit_Click()
Dim Result As VbMsgBoxResult
Dim strMsg As String

Result = MsgBox("Would you like to print a copy of this request?", vbYesNo)
If Result = vbYes Then
Me.Visible = False
DoCmd.OpenReport "Request Report", acViewPreview
WaitForReportClose "Request Report"
End If
strMsg = "Submit another request?"
Result = MsgBox(strMsg, vbYesNo)
If Result = vbYes Then
Me.Visible = True
Else
DoCmd.Close acForm, Me.Name
End If
'DoCmd.Quit acQuitSaveNone
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top