"deko" <www.clearpointsystems.com@use_contact_form.com> wrote in message
news:dl_Id.14992$5R.12339@newssvr21.news.prodigy.c om...[color=blue]
>
> I don't have any loops in mind, but I do have several modules that use[/color]
code[color=blue]
> to assemble SQL strings - complex Update and Select queries with multiple
> joins and parameters from form controls - which seem to run pretty slowly
> when executed with "db.Execute strSqlString".[/color]
Each table added to a query slows it down. As the complexity goes up, the
speed goes down. I'm sure you already know that part, what I'm trying to
say is I don't think you'll find using db.execute "SELECT . . ." and
db.execute existing_QueryDef will have nearly as big an impact as the actual
complexity of the query itself.
Unfortunately, as nice a critter as Access is, it isn't the smartest db
manager on the block, and it will likely never make the best optimization
decisions.
[color=blue]
>
> Based on your suggestion, I'm considering this:
>
> Dim db as DAO.Database
> Dim qItem As QueryDef
> Set db = CurrentDb
> Set qdf = db.QueryDefs
> For Each qItem In qdf
> If qItem.Name = strQry Then Set qItem.SQL = strSql
> qItem.Execute
> Next qItem
>
> This would allow me to dynamically create both the query name and the Sql
> string on the fly with code, and still get the performance of a compiled
> query. Does this sound correct?
>
> But I have over 300 queries - it seems inefficient to have to loop through
> all of them to get the one I want if I know the name of the query. Can[/color]
the[color=blue]
> above loop be improved if I know the name of the qItem I'm looking for?
>
> Also - Intellisense shows an OpenRecordset method for qItem:
>
> qItem.OpenRecordset
>
> Does this mean I can do this:
>
> Set rst = qItem.OpenRecordSet?[/color]
Yes. rst needs to be created first, "dim rst as DAO.Recordset" (and so
on). What you get is a "recordset" that can be iterated through. Sort of a
virtual datasheet (*sort of*). You can use the recordset methods, .edit,
..add, .update, etc. on it. Recordsets are a *big* discussion. (There are
also ADO and RDO versions, as well, which is why you *always* prefix with
the object model you are drawing on, otherwise, problems will occur.)
Since you have Access installed (hopefully 2000+), you also probably have
the following files, which I find invaluable.
DAO360.CHM <--Recordsets are defined in here (along with the rest of
Direct Access Objects 3.6).
JETSQL40.CHM <--SQL for Access is in here.
VBLR6.CHM <--VB 6.0 is in here.
I really can't live without these. :) They are my #1 Resource (followed
by Google's archive of these newsgroups,
www.mvps.org/access/, and several
of the better books). Look through them, they will do you good. The search
function in them for A2000 is hopelessly useless, use the index instead.
DNJET.CHM (Microsoft Jet Database Engine Programmer's Guide), is also very
interesting, but unfortunately, it's for JET 3.5. It still has some useful
info in it.
[color=blue]
> Thanks for the help![/color]
You are welcome. :)