Printing Single Record of Report from Form....

  • Thread starter Thread starter John Keane
  • Start date Start date
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.
 
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
 
Back
Top