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
 

They are both data type 'Short Text'
This is a pretty simple command so I don't understand what I am doing wrong. When I hard-code the value passed from the form (from Debug.Print) directly in the report query, it works. The Open Report command is opening the report, but not passing the Where clause.
 
Yes, that works. But I still can't get the where clause to be passed when the Where clause AuthorizationID is in a set of values returned from a query.
I have:
DoCmd.OpenReport "Expense Report", acViewPreview, , strWhere

strWhere = "[A.AuthorizationId] in (" & reportSQL & ")"

reportSQL = "Select AuthID from (" & strSQL & ")"

strSQL= SELECT * FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like "*Bojko*
 
Are there similar fields name AuthorizationID, AuthID, VoucherID that all store the same text values?

What do you get when you view the results of
Code:
debug.Print strWhere

I would expect strWhere to be something like:
Code:
AuthorizationID in (SELECT AuthID FROM qYourQueryName)

Duane
Hook'D on Access
MS Access MVP
 
I posted it on June 12:

[AuthorizationId] in (Select AuthID from (SELECT * FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like "*Bojko*" ))
 
Does that work if you add it to the SQL of a query?
Why not just use:
Code:
[AuthorizationId] in (Select AuthID FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like "*Bojko*" )

Duane
Hook'D on Access
MS Access MVP
 
I can't do that because the second SELECT clause will change depending on what the user does a search on.
 
What about something like:

strSQL= "SELECT AuthID FROM qryUserAuth WHERE 1 = 1 AND [traveler last name] Like '*Bojko*' "
strWhere = "[A.AuthorizationId] in (" & strSQL & ")"

Duane
Hook'D on Access
MS Access MVP
 
Here is how you can open a report based on a filtered form. This includes allowing the user to apply a filter with the filter menu choice. In other words I do not care how the form gets filtered or how complex that filter is. I just read the keys that are showing on the form.



Code:
Private Sub Command9_Click()
  OpenFilteredReport
End Sub

Public Sub OpenFilteredReport()
  Dim IDs As String
  IDs = GetIDs
  Debug.Print IDs
  ' looks like: ('Company A', 'Company E', 'Company G')
  If IDs = "" Then
    MsgBox "No records selected"
  Else
    DoCmd.OpenReport "rptCustomers", acViewPreview, , "Company in " & IDs
  End If
End Sub

Private Function GetIDs() As String
  Const IDfield = "Company"
  Dim rs As DAO.Recordset
  Set rs = Me.RecordsetClone
  Do While Not rs.EOF
    If GetIDs = "" Then
      GetIDs = "'" & rs.Fields(IDfield) & "'"
    Else
      GetIDs = GetIDs & ", '" & rs.Fields(IDfield) & "'"
    End If
    rs.MoveNext
  Loop
  If Not GetIDs = "" Then GetIDs = "(" & GetIDs & ")"
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top