Print report based on forms selected record

  • Thread starter Thread starter Randy Christiansen
  • Start date Start date
R

Randy Christiansen

Is it possible to print a report based on the selected record of a form
without actually opening the report. I would like to print the record to a
delivery manifest as the user completes the current record. The form name is
frmDelivery and the report name is rptDeliveryPrintOut.

Thank you in advance
 
Is it possible to print a report based on the selected record of a form
without actually opening the report. I would like to print the record to a
delivery manifest as the user completes the current record. The form name is
frmDelivery and the report name is rptDeliveryPrintOut.

Thank you in advance

First create a report that displays all of the data you want to show.

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

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines 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
 
Thank you. I will try that and get back to you.

Thanks again.

fredg said:
Is it possible to print a report based on the selected record of a form
without actually opening the report. I would like to print the record to a
delivery manifest as the user completes the current record. The form name is
frmDelivery and the report name is rptDeliveryPrintOut.

Thank you in advance

First create a report that displays all of the data you want to show.

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

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines 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
 
Your code worked perfectly... thank you very much for your help.

Randy

fredg said:
Is it possible to print a report based on the selected record of a form
without actually opening the report. I would like to print the record to a
delivery manifest as the user completes the current record. The form name is
frmDelivery and the report name is rptDeliveryPrintOut.

Thank you in advance

First create a report that displays all of the data you want to show.

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

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines 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
 
Back
Top