Closing a print preview button after printing

M

Mike

I have a command on a form that prints a report based on a criteria entered
by the user via combo boxes. (there's coding that creates a whereclause for
the report)

i then wanted the print dialog box to open so the user has a selection of
what pages to pring, what printer to use, etc.

to do this from the form, i needed to open the print preview window first,
so the print command would print the report and not the form. now after the
print command runs, i'd like to automatically close the print preview box.

here's my code:

Private Sub RptPrnt_Click()
On Error GoTo Err_RptPrnt_Click

Dim stDocName As String
stDocName = "rptCBReport"

Dim Whereclause As String

If Not IsNull(cbDate) Then
Whereclause = "[Date]='" & cbDate & "'"
End If

If Not IsNull(cbDrawingNumber) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[DrawingNumber] ='" & cbDrawingNumber & "'"
End If

If Not IsNull(cbSerialNumber) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[SerialNumber]='" & cbSerialNumber & "'"
End If

If Not IsNull(cbCustomerPO) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[CustomerPO]='" & cbCustomerPO & "'"
End If

If Not IsNull(cbWireTech) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[WireTech]='" & cbWireTech & "'"
End If

If Not IsNull(cbQATech) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[QATech]='" & cbQATech & "'"
End If

If Not IsNull(cbContractNumber) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[ContractNumber]='" & cbContractNumber & "'"
End If

If Not IsNull(cbCustomer) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[Customer]='" & cbCustomer & "'"
End If

DoCmd.OpenReport stDocName, acViewPreview, , Whereclause
DoCmd.RunCommand acCmdPrint
Rem DoCmd.OpenReport stDocName, acNormal, , Whereclause
(This rem statement was the original print command from the print button)



Exit_RptPrnt_Click:
Exit Sub

Err_RptPrnt_Click:
MsgBox Err.Description
Resume Exit_RptPrnt_Click

End Sub
 
M

Mike

i think i got it. although i don't know why it works

after the DoCmd.Runcoimmand acCmdPrint
i added DoCmd.Close acReport, stDocName

Could someone explain that?

I'm new to basic programming, although i'm prett familiar with c++.

Thank you.




Mike said:
I have a command on a form that prints a report based on a criteria entered
by the user via combo boxes. (there's coding that creates a whereclause for
the report)

i then wanted the print dialog box to open so the user has a selection of
what pages to pring, what printer to use, etc.

to do this from the form, i needed to open the print preview window first,
so the print command would print the report and not the form. now after the
print command runs, i'd like to automatically close the print preview box.

here's my code:

Private Sub RptPrnt_Click()
On Error GoTo Err_RptPrnt_Click

Dim stDocName As String
stDocName = "rptCBReport"

Dim Whereclause As String

If Not IsNull(cbDate) Then
Whereclause = "[Date]='" & cbDate & "'"
End If

If Not IsNull(cbDrawingNumber) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[DrawingNumber] ='" & cbDrawingNumber & "'"
End If

If Not IsNull(cbSerialNumber) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[SerialNumber]='" & cbSerialNumber & "'"
End If

If Not IsNull(cbCustomerPO) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[CustomerPO]='" & cbCustomerPO & "'"
End If

If Not IsNull(cbWireTech) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[WireTech]='" & cbWireTech & "'"
End If

If Not IsNull(cbQATech) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[QATech]='" & cbQATech & "'"
End If

If Not IsNull(cbContractNumber) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[ContractNumber]='" & cbContractNumber & "'"
End If

If Not IsNull(cbCustomer) Then
If Whereclause <> "" Then Whereclause = Whereclause & "AND"
Whereclause = Whereclause & "[Customer]='" & cbCustomer & "'"
End If

DoCmd.OpenReport stDocName, acViewPreview, , Whereclause
DoCmd.RunCommand acCmdPrint
Rem DoCmd.OpenReport stDocName, acNormal, , Whereclause
(This rem statement was the original print command from the print button)



Exit_RptPrnt_Click:
Exit Sub

Err_RptPrnt_Click:
MsgBox Err.Description
Resume Exit_RptPrnt_Click

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