ats said:
I need the results of a query in several other queries. The problem is
that the first query cannot be constructed using SQL, but can be in
VBA. How can I refenence the VBA query results in other queries?
The problem all steams from not being able to use another query or
function results for the "IN" of a query which references direct path
of the external database.
Hi ats,
One method I would use is to save a query (say "qryExtDB"),
(it doesn't matter initially what it's SQL is).
In your VBA, construct the SQL with "IN somepath"
Then change the SQL for the stored query with a public
function in a module, like the following adapted from a
a routine once provided by Duane.
Public Function ChangeSQL(pstrQueryName As String, pstrSQL As String)
On Error GoTo Err_ChangeSQL
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Set db = CurrentDb
Set qd = db.QueryDefs(pstrQueryName)
qd.SQL = pstrSQL
qd.Close
db.Close
Exit_ChangeSQL:
Set qd = Nothing
Set db = Nothing
Exit Function
Err_ChangeSQL:
MsgBox Err.Description
Resume Exit_ChangeSQL
End Function
[NOTE: need to make sure you reference DAO library]
=======================
So...all your other queries are based on "qryExtDB"
=======================
and in your VBA routine you do something like:
'{not password protected}
strSQL = "SELECT * FROM " & pTable _
& " IN '" & pPath & "';"
'{or password protected}
'strSQL = "SELECT * FROM pTable _
' & " IN '' [MS Access;PWD=" & pPWD _
' & ";DATABASE=" & pPath & "];"
'use the function to change SQL of stored query
ChangeSQL("qryExtDB", strSQL)
'or just do it w/o function (again using DAO)
CurrentDb.QueryDefs("qryExtDB").SQL = strSQL
Does that help (or just confuse things)?
gary