My Assistant
![]() ![]() |
|
|
Aug 11 2011, 03:03 PM
Post
#1
|
|
|
UtterAccess Enthusiast Posts: 96 From: Maryland |
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 |
|
|
|
Aug 11 2011, 03:30 PM
Post
#2
|
|
|
Access Wiki and Forums Moderator Posts: 48,058 From: SoCal, USA |
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? |
|
|
|
Aug 11 2011, 03:51 PM
Post
#3
|
|
|
UtterAccess Enthusiast Posts: 96 From: Maryland |
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 |
|
|
|
Aug 11 2011, 04:06 PM
Post
#4
|
|
|
Access Wiki and Forums Moderator Posts: 48,058 From: SoCal, USA |
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... |
|
|
|
Aug 11 2011, 04:26 PM
Post
#5
|
|
|
UtterAccess Enthusiast Posts: 96 From: Maryland |
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 |
|
|
|
Aug 11 2011, 04:39 PM
Post
#6
|
|
|
Access Wiki and Forums Moderator Posts: 48,058 From: SoCal, USA |
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... |
|
|
|
Aug 11 2011, 05:02 PM
Post
#7
|
|
|
UtterAccess Enthusiast Posts: 96 From: Maryland |
That is it! It worked.
Thanks, my little bit of knowledge just got a bit bigger. |
|
|
|
Aug 11 2011, 05:05 PM
Post
#8
|
|
|
Access Wiki and Forums Moderator Posts: 48,058 From: SoCal, USA |
Hi Jamie,
(IMG:style_emoticons/default/yw.gif) Glad to hear you got it to work! Good luck with your project. |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 23rd May 2013 - 05:23 PM |