Print report which matches current record on open form

C

Connie

Hi,

I have placed a button on my form which automatically prints a report based
on the table I am using on the form.

I would like the report to match the current record only. So if I fill out
the form and hit the Print button it will print a report for only the current
record - in other words, matched to the "Requisition Number" field.

Thanks,

Connie
 
F

fredg

Hi,

I have placed a button on my form which automatically prints a report based
on the table I am using on the form.

I would like the report to match the current record only. So if I fill out
the form and hit the Print button it will print a report for only the current
record - in other words, matched to the "Requisition Number" field.

Thanks,

Connie

Your table should have a unique prime key field.
In my example it is named [RecordID].
Change [RecordID] below to whatever your actual field name is.

In the command button's Click event write:

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.

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

Douglas J. Steele

Add a Whereclause to your OpenReport call, indicating the Id of the record
to be printed.
 
C

Connie

Thanks Fred, worked perfect!

Connie :)
[quoted text clipped - 8 lines]

Your table should have a unique prime key field.
In my example it is named [RecordID].
Change [RecordID] below to whatever your actual field name is.

In the command button's Click event write:

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.

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

Top