Printing current record in form

  • Thread starter Alesandro Senerchia
  • Start date
A

Alesandro Senerchia

Hi guys,

I'm new to access and I would like to know how to print/preview a report for
the current record displayed on the screen, without using the file-->print
preview button

The data is in a form, it will contain a preview button.

Thank you in advance

Alesandro
 
A

Allen Browne

In the Click event procedure of your command button, use OpenReport with the
WhereCondition to limit it to the current record.

You need to save the record before the latest edits show in the report, and
there is no current record if the form is at a new record.

The example below shows what to put in the Event Procedure (code) for the
button's Click event. It assumes a numeric primary key named "ID":

Private Sub cmdPreview_Click()
Dim strWhere As String
If Me.Dirty Then 'Save
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Pick a record to print."
Else
strWhere= "[ID] = " & Me.ID
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub
 
Top