Report printing

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

Guest

I have a command button which should print a report from the last record of
the data source.
My VB:

Dim stDocName As String
stDocName =â€receiptâ€
DoCmd.OpenReport stDocName, ac Normal

How can I change this so that the report is only printed for the last record
of the data source and not from all records?

Thanks
Klaus
 
I have a command button which should print a report from the last record of
the data source.
My VB:

Dim stDocName As String
stDocName =¡receipt¡
DoCmd.OpenReport stDocName, ac Normal

How can I change this so that the report is only printed for the last record
of the data source and not from all records?

Thanks
Klaus

Your table should have a unique prime key field.
In my example it is named [RecordID].

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

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

If, however, [RecordID] is Text Datatype, then use:

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

as the Where clause.

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change [RecordID] to whatever the actual field name is that you are
using.

Change acViewPreview to acViewNormal to print without previewing.

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