Printing Reports for individual records

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to be able to print a report for current records that I am
viewing. However, if I try a preview report button, it previews for the
entire database and shows me the first record not the one I was currently
displaying. If I try to print, it trys to print the entire database of
records. Is there anything I can do to print an individual record when I am
currently viewing it?
 
Asked and asnwered alllllll the time.

Please search before posting.



Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.
 
I would like to be able to print a report for current records that I am
viewing. However, if I try a preview report button, it previews for the
entire database and shows me the first record not the one I was currently
displaying. If I try to print, it trys to print the entire database of
records. Is there anything I can do to print an individual record when I am
currently viewing it?

Your table should have a unique prime key field.

If so, code the command button's Click event:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If [RecordID] is Text Datatype, then use:

"[RecordID] = '" & [RecordID] & "'"

as the Where clause.
Change the field name ([RecordID]) to whatever the actual field name
is that you are using.

See Access Help files for:
Where Clause + Restrict data to a subset of records'
 
Back
Top