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.
>