
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. =
<br><br>3) Have you tried using parameter queries?<br><br>Hope =
this helps!<br>-- <br>Ric Vander Ark<br>LORIC Computing & =
Electronics<br>*** Advanced Consulting Solutions =
***<br><br><br><br>Glenn Robbins <<font =
color=3D"#000000">> wrote in article <<font =
<font color=3D"#000000">>...<br>> I'm experiencing some strange =
behavior running queries modified in code<br>> (Access 2.0 running on =
Win95):<br>> <br>> I'm setting some underlying base queries WHERE =
clauses to speed performance<br>> of a complex main query, all works =
OK (until the problem discussed below),<br>> here is how I change one =
of three underlying clauses:<br>> <br>> Set MyQry =3D =
db.QueryDefs("qryForecastBase")<br>> QSQL =3D =
Trim$(MyQry.SQL)<br>> If InStr(QSQL, =
"WHERE ") Then<br>> =
QSQL =3D Left$(QSQL, =
InStr(QSQL, "WHERE ") - 1)'strip any existing <br>> =
End If<br>> =
&=
nbsp; <br>> =
If InStr(QSQL, ";") Then<br>> =
QSQL =3D Left$(QSQL, =
InStr(QSQL, ";") - 1)<br>> End =
If<br>> QSQL =3D QSQL & MyCriteria & ";"<br>> =
MyQry.SQL =3D QSQL<br>> db.QueryDefs.Refresh<br>> <br><br></p>
</font></font></font></font></font></body></html>
------=_NextPart_000_01BC44B4.2067B200--