Printing Single Record of Report from Form....

J

John Keane

Hi

I am getting the following error message in Access 2002.

Run-time error 3079
The specified field ORDER_NO could refer to more than
one table listed in the from clause of your sql statement.

when i run the following code from a button on a
form ..............

Private Sub cmdPrintRecord_Click()
Dim strReportName As String
Dim strCriteria As String

strReportName = "Report2"
strCriteria = "[ORDER_NO]='" & Me![ORDER_NO] & "'"
DoCmd.OpenReport strReportName, acViewPreview, ,
strCriteria
End Sub

i have two tables "tblOrders" with ORDER_NO as Autonumber
Datatype and "tblOrderDetails" with ORDER_NO as Number
Datatype and they are linked 1 to Many.

1) How can i amend the above code to allow me to print
print one record.

2) Can i replace "acViewPreview" with something else so
that i can print the record without previewing it.

I have used the code from article id 209560 on the
Microsoft Web Site.

Many Thanks

John Keane.
 
S

Steve Schapel

John,

Albert's suggestion is a good one. However, it might also imply that
you have included the ORDER_NO field from both your tables in the
query that your report is based on, where you probably only need one.
Also, since ORDER_NO is a number, you shouldn't have the ""s, i.e. it
should be...
strCriteria = "[ORDER_NO]=" & Me![ORDER_NO]

To print the report directly, just omit the acViewPreview, i.e.
DoCmd.OpenReport strReportName, , , strCriteria

- Steve Schapel, Microsoft Access MVP
 

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