Print preview and close form command

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
 
K

Kipp Woodard

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
 
D

Dirk Goldgar

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
 

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