Report printing

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
 
F

fredg

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'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Report printing 1
Report printing 15
Report printing problem 2
Report Missing Data 2
VB code 1
Previewing a report 7
Printing report to PDF file 5
change report using VBA, then view and close it 6

Top