Generate report for a single record

G

Guest

I have a form called PO Form which displays Purchase Order records. I have a
"Print" button for which I want to have the app generate my PO Report for
only the current record being displayed which has a PO No field indicating
the current PO number. I tried to follow the Northwind invoicing printing
sample, but it didn't work and it's not exactly as I want. Northwind prints
the report without first diplaying it on the screen. I've created a query
called PO Filter which SHOULD only select the purchase order record for the
current record being displayed in the PO Form, but I'm not sure if I've set
the criteria correctly ie. [Form]![PO Form]![PO No]
Any assistance would be much appreciated. Thanks!
 
G

Guest

Try this

Dim MyWhereCondition as String
MyWhereCondition= "[PO No] = " & [Form]![PO Form]![PO No]
Docmd.OpenReport "ReportName",acViewPreview,,MyWhereCondition
=======================================
If the [PO No] field is string type add a single quote before and after
MyWhereCondition= "[PO No] = '" & [Form]![PO Form]![PO No] & "'"
=======================================
If you don't want to preview thw report first, and send it to the printer,
drop the acViewPreview from the command line
 
A

Al Camp

h,
You seem to be on the right track regarding filtering the report for a
specific PONo, so I'm not sure where you're having a problem.

In the query behind your PO report, the PONo field should have a criteria
of...
= [Forms]![frmPO Form]![PO No]
That will filter your report to just the associated with the PONo on your
form.

Re printing immediately, use this function to open the report in Preview
mode...
DoCmd.OpenReport "rptYourPONoReportName", acViewPreview
then from the preview view, you can print when you're ready.

Suggestion: avoid using spaces in your Access object names. Names like
frmPOForm or PONo would negate the need for manually bracketing during
coding.
 
G

Guest

One more thing, you need to add s to the form
Instead of : [Form]![PO Form]![PO No]
Change to : [Forms]![PO Form]![PO No]

--
\\// Live Long and Prosper \\//
BS"D


Ofer said:
Try this

Dim MyWhereCondition as String
MyWhereCondition= "[PO No] = " & [Form]![PO Form]![PO No]
Docmd.OpenReport "ReportName",acViewPreview,,MyWhereCondition
=======================================
If the [PO No] field is string type add a single quote before and after
MyWhereCondition= "[PO No] = '" & [Form]![PO Form]![PO No] & "'"
=======================================
If you don't want to preview thw report first, and send it to the printer,
drop the acViewPreview from the command line

--
\\// Live Long and Prosper \\//
BS"D


hfreedman said:
I have a form called PO Form which displays Purchase Order records. I have a
"Print" button for which I want to have the app generate my PO Report for
only the current record being displayed which has a PO No field indicating
the current PO number. I tried to follow the Northwind invoicing printing
sample, but it didn't work and it's not exactly as I want. Northwind prints
the report without first diplaying it on the screen. I've created a query
called PO Filter which SHOULD only select the purchase order record for the
current record being displayed in the PO Form, but I'm not sure if I've set
the criteria correctly ie. [Form]![PO Form]![PO No]
Any assistance would be much appreciated. Thanks!
 

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