Print Preview still visible

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got the following OnClick event in a form to print preview and or print
a report. The only gliche is that the report that is initially previewed
stays
open behind the second prompt for another Project Number. Here's the On click
Event Procedure currently:

Private Sub View_Results_of_Single_Pending_Project_Click()
Const conREPORTNAME = "PROJ HISTORY -ALL PENDING - RPT"
Const conMESSAGE = "Do you wish to print the report?"
Dim strCriteria As String
strCriteria = "[Project Number]=""" & Me.txtProjNo & """"
'hide form
Me.Visible = False
'open report in print preview
DoCmd.OpenReport conREPORTNAME, _
View:=acViewPreview, _
WhereCondition:=strCriteria
'if user confirms, print report
If MsgBox(conMESSAGE, vbQuestion + vbYesNo, "Print Report") = vbYes Then
'close print preview
DoCmd.Close acReport, conREPORTNAME
'print report
DoCmd.OpenReport conREPORTNAME, _
View:=acViewNormal, _
WhereCondition:=strCriteria
End If
'show form
Me.Visible = True
'clear text box ready for next search
Me.txtProjNo = ""
'move focus to report in preview if open
On Error Resume Next
DoCmd.SelectObject acReport, conREPORTNAME
If Err.Number <> 0 Then
DoCmd.OpenForm Me.Name
End If
End Sub

What do I change so that if the user selects "No" to "Do you wish to
print?," the current report being previewed is closed before he is prompted
to enter another Project Number?
 
Add an Else statement into your code to close the report if they click No.

If MsgBox(conMESSAGE, vbQuestion + vbYesNo, "Print Report") = vbYes Then
'close print preview
DoCmd.Close acReport, conREPORTNAME
'print report
DoCmd.OpenReport conREPORTNAME, _
View:=acViewNormal, _
WhereCondition:=strCriteria

ELSE
'close print preview
DoCmd.Close acReport, conREPORTNAME

End If

Hope this helps.

Damian.

ps: Another option would be to give the user two buttons - one to preview
and one to print directly, or to create a custom toolbar that replaces the
default one that simply has print and close on it.
 
Back
Top