> thanks allan. i was aware of the sql code behind the queries and didn't know
> why one wouldn't just point to the query. From a troubleshooting angle, i
[quoted text clipped - 27 lines]
> > >
> > > thanks for all insight and help.
> All other things being equal, I personally think it's better to use
> queries as the source for reports rather than code. I can think of at
> least three reasons: 1) The queries are easier to build and debug,
Why? SQL Statement RecordSources can be viewed in the same graphical query
builder and debugged there. They just do not show up as a saved query
object in the db window. Otherwise they are the same as any othger query.
> 2) there may well be performance benefits as the query execution plan
> will be optimised and stored
No, see above.
> - if the query is created from spliced
> code strings I don't think this happens (though I stand to be
> corrected here); and
I believe the OP was using the word "code" just to refer to SQL Statements
in the RecordSource property. You are correct that if the SQL was built in
VBA code and then assigned on-the-fly that there would be no pre-compiled
plan. On modern hardware it is the rare query where this makes a noticeable
difference however.
> 3), if the report takes a long time to run, for
> debugging purposes you can temporarily change the source query
> source to a 'make table', create a temporary table to base the
> report on while you fix it, then switch the report record source back
> to the original select query.
Can do the same thing with a SQL RecordSource if you just go to the query
designer view of it.
The biggest thing I like about SQL statements instead of saved queries is
that they are self-documenting as to where they are used. While it is easy
to see what saved query a report or form is using, it is not so easy to see
if anything else is using that same saved query so if you want to change it
you might break other stuff. With a SQL statement there is never any doubt
that it is ONLY used by the report or form where you find it.

Signature
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Tom Lake - 28 Mar 2008 19:38 GMT
> The biggest thing I like about SQL statements instead of saved queries is that they
> are self-documenting as to where they are used. While it is easy to see what saved
> query a report or form is using, it is not so easy to see if anything else is using
> that same saved query so if you want to change it you might break other stuff.
> With a SQL statement there is never any doubt that it is ONLY used by the report or
> form where you find it.
I like the saved queries just for that reason! I prefer reusable code so I don't
have to change the SQL statements in multiple places.
Tom Lake
Larry Linson - 31 Mar 2008 04:08 GMT
> I like the saved queries just for that reason! I prefer
> reusable code so I don't have to change the SQL
> statements in multiple places.
I almost never encounter a situation where there is a real need to use the
same query -- and, at times in the past, have tried that, then found that I
had to change either the form or the report that used the query but not the
other.
As far as SQL for RecordSource, as Allen has already pointed out, Access
realizes that SQL in a RecordSource is likely to be used repeatedly, so
"behind the scenes" creates a query from the SQL in the RecordSource and
saves that so it is optimized / compiled / prepared as saved queries are.
If you query the appropriate system table, you'll see those Access-generated
saved queries, the names of which (always/usually) begin with ~.
Where you may find a difference in performance is in SQL created in code and
executed from code... but you'd need a lot of records for the difference to
be discernable on the user's screen. I often use SQL executed from VBA code
against tables with tens of thousands of records, and have sometimes
compared against a saved query, and could see no difference. Thus, I'd say
the "lot of records" would have to be in the hundreds of thousands for it to
make a really discernable difference.
Larry Linson
Microsoft Office Access MVP