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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Callins a report from a form in MS Access 2013 and passing multiple ids 1

Status
Not open for further replies.

InspectorHound

Programmer
Nov 21, 2014
48
US
Hi,

I have an expense report based on a complex query. The report is called from a form that displays a list of people. How do I call the report and pass to it all of the people shown in the form. I am passing a person id so the report will show the expenses related to that person -- but I would like to pass more than one person id.

Thanks
 
The recordsource of the report could be something like

Select Field1, Field2, .... where PersonID in (select PersonID from yourComplexFormQuery)
 
I use a query that selects handful of people (from thousands) based on search criteria entered by the user. I then want the report to use the ten or so IDs displayed on the form to show expense data for these people from another table.
 
Join your report's record source to "query that selects handful of people (from thousands) based on search criteria entered by the user" so you can limit your report results to that group of people.

You can also set a filter like
SQL:
WHERE PeopleID IN (SELECT PeopleID FROM [query that selects handful of people (from thousands) based on search criteria entered by the user])

Duane
Hook'D on Access
MS Access MVP
 
Ok.. Can I do that in the where clause of the DoCmd Open Report statement
 
MajP it's the same concept but instead of in the saved query or report's record source, it is applied to the Filter property of the report using the WHERE CONDITION of the DoCmd.OpenReport method.

Duane
Hook'D on Access
MS Access MVP
 
Ok, but now the where clause is not being passed to the report.
Here is my code:

/********************************************************************
Public Sub cmdReport_Click()
reportSQL = "Select AuthorizationID from (" & strSQL & ")"
MsgBox reportSQL
strWhere = "[Trvl_plng_athrztn.AuthorizationId] in (" & reportSQL & ")"
MsgBox strWhere
DoCmd.OpenReport "Expense Report", acViewPreview, , strWhere
/***********************************************************
What is wrong with this? The record source for the report is a query and the where cluase is not being passed. The report always pulls 14,000 records.
 
Does your code compile?
What is the value of strSQL?
What does the MsgBox display?
Can you place a large text box in your report and set its control source to:
=[Filter]


Duane
Hook'D on Access
MS Access MVP
 
Yes, the code compiles.

The value of strSQL is
*~*~*~*~*~*~*~*~*


Yes, the code compiles.


The value of strSQL is
*~*~*~*~*~*~*~*~*
SELECT * FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like "*Bojko*"
~*~*~*~*~*~*~~*

The Filter box is empty

I am now getting the message that the specdified field "[Trvl_plng_athrztn.AuthorizationId] can refer to more than one table in your from clause.
 
When you stated you wanted to filter for people in a list, it actually meant AuthorizationIDs in a list?

I don't understand what you mean by
InspectorHound said:
The value of strSQL is
*~*~*~*~*~*~*~*~*

Instead of MsgBox strWhere can you use Debug.Print strWhere so you can copy the results for us to see?

Duane
Hook'D on Access
MS Access MVP
 
Fisrt Query that populates form:
SELECT * FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like "*Bojko*"

Second query to get the id number of people displayed on form:
Select AuthID from (SELECT * FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like "*Bojko*" )

The where clause for the report given as strWhere:
[Trvl_plng_athrztn.AuthorizationId] in (Select AuthID from (SELECT * FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like "*Bojko*" ))
 
As I posted in my example you would select one field not *. I'm not sure why you have so many nested queries. I expect your where condition might be something like:
Code:
[AuthorizationId] in (Select AuthID FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like "*Bojko*" )

Duane
Hook'D on Access
MS Access MVP
 
Something must be wrong with the report. Even when I try to pass a single variable, the where clause of the report does not change and all records are returned:
DoCmd.OpenReport "Expense Report", acViewPreview, , "[A.AuthorizationId] = " & Me.VoucherID
 
I'm not sure why you prefix your field name with "A.". Is there more than one field in your report's record source named AuthorizationID? If not, just use:

Code:
DoCmd.OpenReport "Expense Report", acViewPreview, , "[AuthorizationId] = " & Me.VoucherID

Duane
Hook'D on Access
MS Access MVP
 
I get a sytax error in query expression <expression>. (Error 3075)
DoCmd.OpenReport "Expense Report", acViewPreview, , "[AuthorizationId] = " & Me.VoucherID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top