Hello again. 2007
Is it possible to have a button on a report to print the current record?
How is this also achieved with a form? As I recall, I might have to convert the macro option
to print a record to code and then tweak the code to do this? Thanks, Andy.
Print current record
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Print current record
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- Administrator
- Posts: 78531
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Print current record
A report doesn't have a "current" record.
To print the current record in a form, it's best to create a report bound to the same table or query as the form. So by itself, the report will display/print ALL records. Let's say the report is named rptData
Also, let's say that the record source of the form (and report) has a unique identifier named ID, and that this is a number field (for example an AutoNumber field).
You can create a command button cmdReport on the form with an On Click event procedure like this:
This will open the report in preview mode with only the current record from the form. If you prefer to print the report directly instead of previewing it, change acViewPreview to acViewNormal.
To print the current record in a form, it's best to create a report bound to the same table or query as the form. So by itself, the report will display/print ALL records. Let's say the report is named rptData
Also, let's say that the record source of the form (and report) has a unique identifier named ID, and that this is a number field (for example an AutoNumber field).
You can create a command button cmdReport on the form with an On Click event procedure like this:
Code: Select all
Private Sub cmdReport_Click()
If IsNull(Me.ID) Then
MsgBox "There is no current record.", vbExclamation
Else
DoCmd.OpenReport "rptData", acViewPreview, , "ID = " & Me.ID
End If
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: Print current record
That's terrif. Thanks, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.