mick_green
New member
- Local time
- Today, 08:32
- Joined
- Oct 8, 2021
- Messages
- 2
Hi,
I'm looking for assistance with queries / VBA coding - not sure which discussion this best belongs in really...
For background, I have a number of queries which run in succession as they would be too complicated to have as one query or given the limitations of Access which would not allow it. So, I am "stuck" with a number queries but this question is really to do with calling them rather than what each one actually does.
The first question is to do with passing a parameter to the where clause of the first query, which looks like this:
and I am calling it like this:
the problem is that no results are returned. I have a suspicion that this is to do with
Does anyone know a solution to this as it would be useful to know for other queries which can be run on their own?
Now I could forgo having them as queries, which is useful as I can call with different parameters everytime I need different data, and code them in VBA but my next question is if I did that, how do I run a query on the recordset of a previous query? So, if I need to run 3 queries, I can run the first which gives me a recordset, but the second query needs to use the results of the first query...
I'm looking for assistance with queries / VBA coding - not sure which discussion this best belongs in really...
For background, I have a number of queries which run in succession as they would be too complicated to have as one query or given the limitations of Access which would not allow it. So, I am "stuck" with a number queries but this question is really to do with calling them rather than what each one actually does.
The first question is to do with passing a parameter to the where clause of the first query, which looks like this:
Code:
SELECT A1,B1,C1,D2
FROM tblSelection
WHERE (Selection In ([@Param2]))
and I am calling it like this:
Code:
Private Sub ParamTest()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qr As DAO.QueryDef
Set db = CurrentDb
Set qr = db.QueryDefs("ParamTest")
qr.Parameters("@Param2").Value = "'10A','10B','10C'"
Set rs = qr.OpenRecordset
Do While Not rs.EOF
Debug.Print rs.Fields(1).Value
rs.MoveNext
Loop
Debug.Print
End Sub
the problem is that no results are returned. I have a suspicion that this is to do with
qr.Parameters("@Param2").Value = "'10A','10B','10C'"
because if I change it to qr.Parameters("@Param2").Value = "'10A'"
, I get results back, so I think it is to do with the list of strings???Does anyone know a solution to this as it would be useful to know for other queries which can be run on their own?
Now I could forgo having them as queries, which is useful as I can call with different parameters everytime I need different data, and code them in VBA but my next question is if I did that, how do I run a query on the recordset of a previous query? So, if I need to run 3 queries, I can run the first which gives me a recordset, but the second query needs to use the results of the first query...