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 / June 2006

Tip: Looking for answers? Try searching our database.

Printing a report from a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
baffled - 05 Jun 2006 22:36 GMT
without opening to preview the report I would like the report to print from
the command button on the form. this is the last field before going to the
next record. the autonumber field is the unigue identifier. i keep getting
all the records printing out instead of just the one with focus. i tried
several docmds that have been suggested, but with no luck so far.

Klatuu - 05 Jun 2006 22:51 GMT
You need to use the Where argument to tell the report to print only the
current record.  Since I don't know the names of your table fields or form
controls, I will use the following as examples.  You will need to change the
name to yours.

DoCmd.OpenReport "MyReportName", acNormal, , "[AUTO_NUMBER_FIELD] = " &
Me.txtAutoNumber

MyReportName = The name of your report.
acNormal means go straight to the printer
[AUTO_NUMBER_FIELD] = the field in your table that is the primary key
txtAutoNumber = the control on your form that is the primary key of the
record you want to print.

Now, there is one other thing to consider.  If this is a brand new record
you have just entered, the report will not find it because it is not yet in
the table.  It is only in the form's recordset.  To get it into the table,
you will need requery the form.  The problem here is that whenever you do a
form requery, the recordset goes back to the first record in the recordset,
so you need to reposition your form to the record you were on.  Here is some
"air" code to do that.

If Me.NewRecord then
   lngKeyValue = Me.txtAutoNumber
   Me.Requery
   set rst = Me.RecordsetClone
   rst.FindFirst "[AUTO_NUMBER_FIELD] = " & lngKeyValue
   Me.BookMark = rst.Bookmark
   set rst = Nothing
End If

> without opening to preview the report I would like the report to print from
> the command button on the form. this is the last field before going to the
> next record. the autonumber field is the unigue identifier. i keep getting
> all the records printing out instead of just the one with focus. i tried
> several docmds that have been suggested, but with no luck so far.
>  
Steve Schapel - 06 Jun 2006 08:58 GMT
Did the DoCmds you tried include these?...
 DoCmd.RunCommand acCmdSaveRecord
 DoCmd.OpenReport "YourReport", , , "AutonumberField=" & Me.AutonumberField

Signature

Steve Schapel, Microsoft Access MVP

> without opening to preview the report I would like the report to print from
> the command button on the form. this is the last field before going to the
> next record. the autonumber field is the unigue identifier. i keep getting
> all the records printing out instead of just the one with focus. i tried
> several docmds that have been suggested, but with no luck so far.
>  
 
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.