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
Rick B - 16 May 2005 18:44 GMT
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.

Signature
Rick B
> I am using the following code to print a report from a query.
>
[quoted text clipped - 11 lines]
>
> Dave
Duane Hookom - 16 May 2005 18:44 GMT
DoCmd.Save isn't doing what you would expect. Use:
docmd.RunCommand acCmdSaveRecord

Signature
Duane Hookom
MS Access MVP
>I am using the following code to print a report from a query.
>
[quoted text clipped - 11 lines]
>
> Dave
fredg - 16 May 2005 20:19 GMT
> I am using the following code to print a report from a query.
>
[quoted text clipped - 11 lines]
>
> 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.

Signature
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
DaveA - 16 May 2005 20:44 GMT
Thank you. The DoCmd.RunCommand worked perfectly.
Dave