Print current record

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Print current record

Post by agibsonsw »

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.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Print current record

Post by HansV »

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:

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
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.
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Print current record

Post by agibsonsw »

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.