Print current record

Print current record

Postby agibsonsw » 10 May 2010, 12:07

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.
Post=15793
User avatar
agibsonsw
SilverLounger
 
Posts: 2026
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Print current record

Postby HansV » 10 May 2010, 12:27

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.
Regards,
Hans
Post=15797
User avatar
HansV
Clever Clogs
 
Posts: 24188
Joined: 16 Jan 2010, 00:14
Location: Leiden, The Netherlands

Re: Print current record

Postby agibsonsw » 10 May 2010, 14:31

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.
Post=15801
User avatar
agibsonsw
SilverLounger
 
Posts: 2026
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND


Return to Access/SQL

Who is online

Users browsing this forum: CCBot [Bot] and 0 guests