Good morning Rick,
I understand what you're saying, but haven't seen it as I don't store
queries. What I do in cases of complex SQL is assign the Recordsource via
VBA in On_Open events - this seems to be MUCH faster, especially with
complex joins. For instance, for one report, the following SQL joins 4
tables; using the SQL directly in the form's recordsource takes approx 5
seconds to load. As a test, I saved the SQL as a stored query - as you said,
same performance:
SELECT [tblPMO].[RepNum], [tblPMO].[Title], [tblLSGCode].[MCODE],
[tblPMO].[SubForApp], [tblSched].[LCode], [tblLSGCode].[TITLE],
[tblLSGCode].[NARR], [tblLSGCode].[ManHours],
[tblCauseCodes].[CauseCode],
[tblPMO].[Author] FROM tblPMO INNER JOIN ((tblLSGCode INNER JOIN
tblCauseCodes ON [tblLSGCode].[LCode]=[tblCauseCodes].[LSGCode]) INNER JOIN
tblSched ON [tblLSGCode].[LCode]=[tblSched].[LCode]) ON
[tblPMO].[RepNum]=[tblSched].[RepNum] WHERE ((([tblSched].[OpStat])='FOS'));
On the other hand, using this VBA instead, the form opens in
milliseconds:
Private Sub Report_Open(Cancel As Integer)
Dim src As String
src = "SELECT [tblPMO].[RepNum], [tblPMO].[Title], [tblLSGCode].[MCODE],
" _
& "[tblPMO].[SubForApp], [tblSched].[LCode],
[tblLSGCode].[TITLE], "
_
& "[tblLSGCode].[NARR], [tblLSGCode].[ManHours],
[tblCauseCodes].[CauseCode], " _
& "[tblPMO].[Author], [tblSched].[LOM] FROM tblPMO INNER JOIN " _
& "((tblLSGCode INNER JOIN tblCauseCodes ON
[tblLSGCode].[LCode]=[tblCauseCodes].[LSGCode]) " _
& "INNER JOIN tblSched ON
[tblLSGCode].[LCode]=[tblSched].[LCode])
ON " _
& "[tblPMO].[RepNum]=[tblSched].[RepNum] WHERE
((([tblSched].[OpStat])='FOS') " _
& "And (([tblSched].[LOM])='L4')); "
Me.RecordSource = src
DoCmd.Maximize
End Sub
Why is there such a difference?
SusanV <~~ wants to understand the nuts and bolts, not just "how-to"
Rick Brandt said:
SusanV wrote:
Yep - that's how I have most of the multi-table forms set up. I've
noticed though that that tends to cause some slow performance opening
some forms...
There should be no difference in performance between using a SQL Statement
for your Form's RecordSource compared to using a saved query that contains
the same SQL. Saved queries have a slight performance advantage compared
to SQL statements that are generated on the fly in code, but those
differences don't exist when compared to SQL Statements in Form or Report
RecordSources. Those have saved optimization plans exactly the same as
saved queries do.