Full Version: Print Or Print Preview Current Record
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
savingryan
Using Access 2007
Goal: To Print or Print Preview a report showing only the current record's information.

Using the OnClick Event Procedure on a button in the Main Form I attached this code (sorry if I posted the code incorrectly, please correct me if I did)

Private Sub Command80_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim strDocName As String
Dim strWhere As String
strDocName = "rptLEGAL"
strWhere = "[ORDERID1]=" & Me!ORDERNUMBER
DoCmd.OpenReport strDocName, acViewPreview, , strWhere
End Sub

It does not work, I'm asked to Enter Parameter Value ORDERID1.

ORDERID1 is a text box and also the Link Master Field on my report where the OrderID fields on all subreports are Link Child Fields.
ORDERNUMBER is a field on the Main Form.

Hopefully someone can help me see where my error lies.

Thanks,
Jamie
theDBguy
Hi Jamie,

Do you have a field in your table called "ORDERID1?" If not, what is the name of the primary key field in your table?
savingryan
Do you have a field in your table called "ORDERID1?" If not, what is the name of the primary key field in your table?

No, "ORDERID1" is the name of the text field on the report, the control source for that field is tblOrders.ORDERID. The primary key field in the table "tblOrders" is "OrderID"

Thanks
theDBguy
Thanks. In that case, try changing your code to something like:

strWhere = "[OrderID]=" & Me!ORDERNUMBER

or

strWhere = "[OrderID]=" & Me!ORDERID1


Not quite sure which one is appropriate for your setup.

Hope that helps...
savingryan
Thanks, I get this error after I tried changing it to "OrderID". This happened to me before which is why I named the field on the report OrderID1, thinking it would fix this isse.

"The specified field '[ORDERID]' could refer to more than one table listed in the FROM clause of your SQL statement."

Which leads me to believe my initial naming of fields in the tables was done incorrectly. That is to say I used the name OrderID in my main table and all the tables that have a relationship with the main table.

The report has several sub reports that all link using the field "OrderID" I named the one field on the report ORDERID1 thinking it would fix the above error. I feel like I need to drop back and punt! (start all over!!)

Any ideas?

Thanks
theDBguy
Hi,

If your report's record source includes multiple fields named "OrderID" from different tables, then you'll need to specify which one you want to filter against. For example, try changing your code to:

strWhere = "[TableName].[OrderID]=" & Me!ORDERID1

Hope that helps...
savingryan
That is it! It worked.

Thanks, my little bit of knowledge just got a bit bigger.
theDBguy
Hi Jamie,

yw.gif

Glad to hear you got it to work!

Good luck with your project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.