Sub SetQryProperty(strQryName as String, _
strPropertyName as String, _
varNewSetting as Variant)
Dim qdf as DAO.QueryDef
For Each qdf In CurrentDb.QueryDefs
If qdf.Name = strQryName Then
qdf.Properties(strPropertyName) = varNewSetting
Exit For
End If
Next qdf
Set qdf = Nothing
End Sub
You'd paste this sub procedure into a module and call it
in code like this...
SetQryProperty "qryName", "prpName", "prpSetting"
Don't forget to reference the DAO 3.6 Object Library.
Good luck.
>.
>
>.
>
>.
>
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)
"john acocella" <jaco...@hotmail.com> wrote in message
news:120bb01c410fe$c66c2410$a401...@phx.gbl...
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)
"john acocella" <jaco...@hotmail.com> wrote in message
news:1207e01c41100$bd7ca030$a301...@phx.gbl...
> Actually it did find the query, but when I pass
> the "Source Database" property, I get an error
> message "Property does not exist"
...
>>> qdf.Properties(strPropertyName) = varNewSetting
You need to read the help files on the DAO Properties collection. Not all
properties exist until you have something to put in them, and attempts to
read or write non-existent properties raise a trappable error. You can
intercept this error and create the property using the appropriate method
call. It's well documented with examples.
In any case, surely the source of data is part of the SQL text of the query
itself. Dont you have it in an IN clause?
HTH
Tim F
>.
>
Setting the property in the query design view simply
modifies the query's SQL by adding to the query's FROM
clause
eg) with property set;
FROM tblMyTable IN 'C:\MyDatabase.mdb'
without property set;
FROM tblMyTable
You could use the sub procedure I gave you earlier to
modify the query's SQL property.
strDbPath = "C:\MyDatabase.mdb"
strSQL = "SELECT tblMyTable.* " _
& "FROM tblMyTable IN '" & strDbPath & "'"
SetQryProperty "qryName", "SQL", strSQL
good luck.
>.
>
If I write code to modify the SQL in code as you suggest,
then I might as well just copy and paste the SQL from the
Access window to VBA and just insert a variable in place
of the file location and get rid of the defined query
alltogether since I would be over writing the SQL using
your approach.
>.
>
>.
>
stSrcTbl ="C:\DBName.mdb"
db.Execute stSQL
set db=nothing
"John Acocella" <jaco...@hotmail.com> wrote in message
news:d6aa01c410ef$1bd57a60$a001...@phx.gbl...
(snip)
> Thanks...I knew that setting this property appended the
> SQL. I guess like you said you can't access defined query
> properties via Querydef. If my memory serves me you can
> change properites of a form via code ie "Record Source".
> Don't understand why I can't change a query property.
You >can< change querydef properties. However, despite what the query grid
may say, "source database" is >not< a property of any querydef object. Look
up querydef object in online help, click the properties button, & you will
not see an entry for "source database".
Conversely, "recordsource" >is< a property of a form object. You >will< see
that property listed in online help, for the form object.
HTH,
TC