Strange Behavior with queries in code 
Author Message
 Strange Behavior with queries in code

I'm experiencing some strange behavior running queries modified in code
(Access 2.0 running on Win95):

I'm setting some underlying base queries WHERE clauses to speed performance
of a complex main query, all works OK (until the problem discussed below),
here is how I change one of three underlying clauses:

Set MyQry = db.QueryDefs("qryForecastBase")
QSQL = Trim$(MyQry.SQL)
    If InStr(QSQL, "WHERE ") Then
        QSQL = Left$(QSQL, InStr(QSQL, "WHERE ") - 1)'strip any existing
    End If

    If InStr(QSQL, ";") Then
        QSQL = Left$(QSQL, InStr(QSQL, ";") - 1)
    End If
QSQL = QSQL & MyCriteria & ";"
MyQry.SQL = QSQL
db.QueryDefs.Refresh

Now I open the main query:
Set RS = db.OpenRecordset("ShellReport", DB_OPEN_SNAPSHOT)

All runs fine. Now the problem: if the user hits the button to run this
procedure again, the error "Query Too Complex" is generated when it
attempts to open the recordset (even on the same criteria).  If the user
then clicks 'OK' on the error message, and AGAIN tries to run the
procedure, all is OK; or If you leave Acces and come back, you can run it
again.

It's a Form procedure that is running, I close the recordset, set MyQry to
nothing, etc., but Access is doing something funny with the code, something
that generating an error once seems to correct.  Any help on what's
happening or how to work around would be appreciated.
GR



Fri, 24 Sep 1999 03:00:00 GMT  
 Strange Behavior with queries in code

This is a multi-part message in MIME format.

------=_NextPart_000_01BC44B4.2067B200
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

I'm not sure where the problem is, but here are a few suggestions to
troubleshoot:
1) What is MyCriteria? How does that get created?

2) you need to compare the query before and after your mods. Before the
MyQry.SQL = QSQL line, do a Debug.Print QSQL and then copy the result to a
new query in SQL view.  

3) Have you tried using parameter queries?

Hope this helps!
--
Ric Vander Ark
LORIC Computing & Electronics
*** Advanced Consulting Solutions ***



Quote:
> I'm experiencing some strange behavior running queries modified in code
> (Access 2.0 running on Win95):

> I'm setting some underlying base queries WHERE clauses to speed
performance
> of a complex main query, all works OK (until the problem discussed
below),
> here is how I change one of three underlying clauses:

> Set MyQry = db.QueryDefs("qryForecastBase")
> QSQL = Trim$(MyQry.SQL)
>     If InStr(QSQL, "WHERE ") Then
>         QSQL = Left$(QSQL, InStr(QSQL, "WHERE ") - 1)'strip any existing
>     End If

>     If InStr(QSQL, ";") Then
>         QSQL = Left$(QSQL, InStr(QSQL, ";") - 1)
>     End If
> QSQL = QSQL & MyCriteria & ";"
> MyQry.SQL = QSQL
> db.QueryDefs.Refresh

------=_NextPart_000_01BC44B4.2067B200
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<html><head></head><BODY bgcolor=3D"#FFFFFF"><p><font size=3D3 =
color=3D"#000000" face=3D"Arial">I'm not sure where the problem is, but =
here are a few suggestions to troubleshoot:<br>1) What is MyCriteria? =
How does that get created?<br><br>2) you need to compare the query =
before and after your mods. Before the MyQry.SQL =3D QSQL line, do a =
Debug.Print QSQL and then copy the result to a new query in SQL view. =
&nbsp;<br><br>3) Have you tried using parameter queries?<br><br>Hope =
this helps!<br>-- <br>Ric Vander Ark<br>LORIC Computing &amp; =
Electronics<br>*** Advanced Consulting Solutions =
***<br><br><br><br>Glenn Robbins &lt;<font =

color=3D"#000000">&gt; wrote in article &lt;<font =

<font color=3D"#000000">&gt;...<br>&gt; I'm experiencing some strange =
behavior running queries modified in code<br>&gt; (Access 2.0 running on =
Win95):<br>&gt; <br>&gt; I'm setting some underlying base queries WHERE =
clauses to speed performance<br>&gt; of a complex main query, all works =
OK (until the problem discussed below),<br>&gt; here is how I change one =
of three underlying clauses:<br>&gt; <br>&gt; Set MyQry =3D =
db.QueryDefs(&quot;qryForecastBase&quot;)<br>&gt; QSQL =3D =
Trim$(MyQry.SQL)<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;If InStr(QSQL, =
&quot;WHERE &quot;) Then<br>&gt; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QSQL =3D Left$(QSQL, =
InStr(QSQL, &quot;WHERE &quot;) - 1)'strip any existing <br>&gt; =
&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&gt; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&gt; =
&nbsp;&nbsp;&nbsp;&nbsp;If InStr(QSQL, &quot;;&quot;) Then<br>&gt; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QSQL =3D Left$(QSQL, =
InStr(QSQL, &quot;;&quot;) - 1)<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;End =
If<br>&gt; QSQL =3D QSQL &amp; MyCriteria &amp; &quot;;&quot;<br>&gt; =
MyQry.SQL =3D QSQL<br>&gt; db.QueryDefs.Refresh<br>&gt; <br><br></p>
</font></font></font></font></font></body></html>
------=_NextPart_000_01BC44B4.2067B200--



Sun, 26 Sep 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Strange problem running Queries in Code

2. MoveFirst, MoveLast strange behavior

3. Strange Subform Record Behavior

4. word mail merge strange behavior

5. Strange behavior with INT function

6. strange behavior

7. Strange behavior in Add-Ins

8. Strange Behavior

9. V7 Strange behavior after text import.

10. Acc 97 Strange Table Behavior

11. Access 2.0-Strange behavior when using arrays and UPDATE command

12. Access Developers Handbook - Strange Form Behavior

 

 
Powered by phpBB® Forum Software