Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Report Pages

Status
Not open for further replies.

LadyDev

Programmer
Jan 29, 2003
86
US
I found this code on mvps.org (reports section). It's supposed to allow you to print only the current (or one page) at a time from a report. I keept getting this error "can't identify or find RunID in expression". Does anyone know what the RunID in this code means?
Thanks!

Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere
 
that's a good question as to why it isn't working... because I've tried the code using string and numberic values, and it works fine. You code assumes numeric (no delimiters) for RunID, and I get a differnt Error Message if I mixed Field Types (Data type mismatch in criteria expression). Also if the form is closed you get an "Invalid Use of Me Keyword" error and attempting to print an unsaved record returns an error message based on the info entered. So, it might be with the recordset you use on the form that you are calling this from, other than that.. not a clue.

If the recordsource for the report is a query, post the sql statement, if the recordsource for the form is a query, post the sql statement for that, also give us the name of the control that RunID is bound to in the form.

PaulF
 
' strDocName is the name of your report
Dim strDocName As String
' strWhere is the criteria for the report, this would be
'the current record filter
Dim strWhere As String
' this is how you set the string for the report name
' you would place your report in between the quotes
strDocName = "rptSomeReport"
' this is how you set the criteria, you would place
' the name of the current record , it might
' customerID, or OrderID, or something like that.
' the "[RunID} = " part is the field from the table,
' the me!RunID is a control from the form, the me!RunID
' doesn't have
' to be the same name as the "[RunID] = ", but it does
' have to be the same data type.
' You will have to change the RUNID to match your fields
' and controls

strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere

-Mark

Mark P.

Bleh
 
What??? Okay, now I am really confused!

Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport" (rptVisitRequest)
strWhere = "[RunID]=" & me!RunID (AddressID)
DoCmd.OpenReport strDocName, acPreview, , strWhere

I have the code bound to a cmdbutton named PrintReport on a form named Personnel, whose source is a query named qryPerStatus. My report name is rptVisitRequest.
 

Dim strDocName as String
Dim stWhere as String

strDocName = "rptVisitRequest"
strWhere = "[AddressID] = " & me![AddressID]

you need to have a textbox on the form personnel named AddressID, you need to have a field in the query named AddressID.


Mark P.

Bleh
 
Before (even though it printed all the reports) the form automatically printed. Now it just opens for preview, then I have to select File/Print. Is this what is supposed to happen? This is how I have my code setup on the form. Thanks!


Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click

Dim strDocName As String
Dim strWhere As String
strDocName = "rptVisitRequest2"
strWhere = "[AddressID]=" & Me!AddressID
DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_PrintReport_Click:
Exit Sub

Err_PrintReport_Click:
MsgBox Err.Description
Resume Exit_PrintReport_Click

End Sub
 
DoCmd.OpenReport strDocName, acPreview, , strWhere



to print:
DoCmd.OpenReport strDocName, acPrint, , strWhere


It's more helpfull if you just type out the line rather then copy and paste. There are all sorts of options that appear as you type in the code. That's how I learned about a lot of things.

Mark P.

Bleh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top