Report not printing unless I exit form and reload

  • Thread starter Thread starter nydiroth
  • Start date Start date
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
 
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.
 
DoCmd.Save isn't doing what you would expect. Use:
docmd.RunCommand acCmdSaveRecord
 
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.
 
Back
Top