VBA in Access ... sql statement with querydef 
Author Message
 VBA in Access ... sql statement with querydef

I am having a problem where the SQL source is removing /
treating an ampersand (&) as a concating one instead of a
litteral string.

Here is some of the code:

strSQL = strSQL & "((Format(Trim([fldShipMonth]) & '/01/'
& Trim([fldShipYear]),'Short Date')) >= #" & dteStartDate
& "#)"

if I do a msgbox on the strSQL it returns what I am
looking for:

Format(Trim([fldShipMonth]) & '/01/' & Trim
([fldShipYear]),'Short Date')) >= #1/01/01#)

but when I pass it to the query def (myQueryDef.SQL =
strSQL) it changes it to:

Format(Trim([fldShipMonth]) & '/01/' Trim
([fldShipYear]),'Short Date')) >= #1/01/01#)

Notice the lack of the second ampersand.  

Has anyone else had this problem or know of a possible
solution.  I have tried send the character set equivelents
chr(38) and chr(34) for the quotes and ampersands but it
gives the same results.

Here are my definitions:

This is declare at the form level
Dim dteStartDate As Date

These are declared in a public module
Public myQueryDef As QueryDef
Public strSQL As String

I have also included the Microsoft DAO 3.6 Object Library



Mon, 08 Dec 2003 01:18:32 GMT  
 VBA in Access ... sql statement with querydef
I figured it out ... the problem was with a previous
declaration of the same statemtent in the SELECT portion.

Quote:
>-----Original Message-----
>I am having a problem where the SQL source is removing /
>treating an ampersand (&) as a concating one instead of a
>litteral string.

>Here is some of the code:

>strSQL = strSQL & "((Format(Trim([fldShipMonth]) & '/01/'
>& Trim([fldShipYear]),'Short Date')) >= #" & dteStartDate
>& "#)"

>if I do a msgbox on the strSQL it returns what I am
>looking for:

>Format(Trim([fldShipMonth]) & '/01/' & Trim
>([fldShipYear]),'Short Date')) >= #1/01/01#)

>but when I pass it to the query def (myQueryDef.SQL =
>strSQL) it changes it to:

>Format(Trim([fldShipMonth]) & '/01/' Trim
>([fldShipYear]),'Short Date')) >= #1/01/01#)

>Notice the lack of the second ampersand.  

>Has anyone else had this problem or know of a possible
>solution.  I have tried send the character set
equivelents
>chr(38) and chr(34) for the quotes and ampersands but it
>gives the same results.

>Here are my definitions:

>This is declare at the form level
>Dim dteStartDate As Date

>These are declared in a public module
>Public myQueryDef As QueryDef
>Public strSQL As String

>I have also included the Microsoft DAO 3.6 Object Library

>.



Mon, 08 Dec 2003 01:40:22 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Access: Err 2342 in SQL SELECT Statement in VBA

2. Access: Err 2342 in SQL SELECT Statement in VBA

3. Parameters from VB6 to ACCESS VBA SQL-statement

4. set variable with an sql statement in VBA

5. SQL Statement in a VBA procedure

6. SQL statement from VBA

7. VBA Functions in SQL Statement

8. Do SQL statements work in VBA?

9. How to execute a SQL statement with VBA ?

10. VBA SQL statement

11. Access 2000 VBA/SQL - cannot create pseudo-index on linked SQL Server table

12. If statement in Access VBA

 

 
Powered by phpBB® Forum Software