Report not printing unless I exit form and reload

N

nydiroth

I am using the following code to print a report from a query.

Dim stDocName As String

DoCmd.Save
Me.Refresh
stDocName = "PropertyReportRpt"
DoCmd.OpenReport stDocName, acNormal


The problem is that if I enter the information in the form and click
print, it prints an empty report. If I close the report and reopen it
or if I change to another record and return, it prints fine. Is there
something I can do to print without closing the form.

Dave
 
R

Rick B

Not sure. Does DoCmd.Save actually save the record? I have never used that
code before.

Personally, I'd put more error checking. Here is the code I use...




Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.
 
D

Duane Hookom

DoCmd.Save isn't doing what you would expect. Use:
docmd.RunCommand acCmdSaveRecord
 
F

fredg

I am using the following code to print a report from a query.

Dim stDocName As String

DoCmd.Save
Me.Refresh
stDocName = "PropertyReportRpt"
DoCmd.OpenReport stDocName, acNormal

The problem is that if I enter the information in the form and click
print, it prints an empty report. If I close the report and reopen it
or if I change to another record and return, it prints fine. Is there
something I can do to print without closing the form.

Dave

DoCmd.Save saves changes made to the form design, not changes to the
record.
Use:
DoCmd.RunCommand acCmdSaveRecord

The Me.Refresh is not needed to open the report.
 

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