close current form when previewing a report

D

deb

I have a problem....I have a command button on a form
that will open a preview report. However, when I click
on it, it opens the report, but the form still stays on
top. I would like to form to go away after the report is
open. I put a docmd.close command in the button and then
it gives me an error....what am I doing wrong???

----------------------------

Option Compare Database

Private Sub talking_books_preview_Click()
On Error GoTo Err_talking_books_preview_Click

Dim stDocName As String
Me.Refresh
(this is where I try to put the docmd.close)

stDocName = "rpt-talking books-all"
DoCmd.OpenReport stDocName, acPreview, , "studentid="
& StudentID

Exit_talking_books_preview_Click:
Exit Sub

Err_talking_books_preview_Click:
MsgBox Err.Description
Resume Exit_talking_books_preview_Click

End Sub
 
R

Rick

Try specifying which form to close...

DoCmd.Close acForm, "FrmSwitchboardReports"

Change FrmSwitchboardReports to the name of your form. I have my statement
AFTER the part of the code that opens the form.

Rick
 
F

fredg

I have a problem....I have a command button on a form
that will open a preview report. However, when I click
on it, it opens the report, but the form still stays on
top. I would like to form to go away after the report is
open. I put a docmd.close command in the button and then
it gives me an error....what am I doing wrong???

----------------------------

Option Compare Database

Private Sub talking_books_preview_Click()
On Error GoTo Err_talking_books_preview_Click

Dim stDocName As String
Me.Refresh
(this is where I try to put the docmd.close)

stDocName = "rpt-talking books-all"
DoCmd.OpenReport stDocName, acPreview, , "studentid="
& StudentID

Exit_talking_books_preview_Click:
Exit Sub

Err_talking_books_preview_Click:
MsgBox Err.Description
Resume Exit_talking_books_preview_Click

End Sub

What's with Me.Refresh?
If you are trying to run the report after entering new data:
DoCmd.RunCommand acCmdSaveRecord
would be better.

DoCmd.RunCommand acCmdSaveRecord
Dim stDocName As String
stDocName = "rpt-talking books-all"
DoCmd.OpenReport stDocName, acPreview, , "studentid=" & StudentID
DoCmd.Close acForm, Me.Name
 

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