Print preview and close form command

  • Thread starter Thread starter Arlene
  • Start date Start date
A

Arlene

Hi,

I tried everything that I could think of to make this work and still have
problems with it.

I created a form to open a print preview report that is based on a query
(criteria selected from a combo box on the form).
I need that once the criteria is selected and the report is open, that the
form close by itself. I tryied the DoCmd.Close and DoCmd.Close(acForm,[Select
Unit Classification]) and it is not working. Can anyone help me please? This
is what I have in my MVS

Private Sub Command9_Click()
On Error GoTo Err_Command9_Click

Dim stDocName As String

stDocName = "Rpt Position Summary by Unit Class"
DoCmd.OpenReport stDocName, acPreview

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click

End Sub
 
Try this:

Private Sub Command9_Click()
On Error GoTo Err_Command9_Click

Dim stDocName As String

stDocName = "Rpt Position Summary by Unit Class"
DoCmd.OpenReport stDocName, acPreview

DoCmd.SelectObject acForm, "<YourFormName>"
DoCmd.Close

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click

End Sub
 
Arlene said:
Hi,

I tried everything that I could think of to make this work and still have
problems with it.

I created a form to open a print preview report that is based on a query
(criteria selected from a combo box on the form).
I need that once the criteria is selected and the report is open, that the
form close by itself. I tryied the DoCmd.Close and
DoCmd.Close(acForm,[Select
Unit Classification]) and it is not working. Can anyone help me please?
This
is what I have in my MVS

Private Sub Command9_Click()
On Error GoTo Err_Command9_Click

Dim stDocName As String

stDocName = "Rpt Position Summary by Unit Class"
DoCmd.OpenReport stDocName, acPreview

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click

End Sub


Try this:

DoCmd.OpenReport stDocName, acPreview
DoCmd.Close acForm, Me.Name, acSaveNo
 
Back
Top