Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / May 2005

Tip: Looking for answers? Try searching our database.

Report not printing unless I exit form and reload

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nydiroth@yahoo.com - 16 May 2005 18:36 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.