adding AND to a SQL statement 
Author Message
 adding AND to a SQL statement

    Set dBSop = CurrentDb

    strSQLSop = "SELECT ORDER_NUMBER, CUST_ORDER_NUMBER From
tblSALES_ORDERcopy WHERE [CUST_ORDER_NUMBER] Like '*" & Me![Warranty No] &
"'"

    Set rSSop = dBSop.OpenRecordset(strSQLSop, dbOpenDynaset)

I need to add an AND statement to strSQLSop so that it searches on
Me![AccCode] as well (this is a text field)

    strSQLSop = "SELECT ORDER_NUMBER, CUST_ORDER_NUMBER From
tblSALES_ORDERcopy WHERE [CUST_ORDER_NUMBER] Like '*" & Me![Warranty No] &
"'" & " AND [CUST_REF] = '" & Me![AccCode] & "'"

But this does not seem to work

Any ideas?
--
Moiz



Thu, 16 May 2002 03:00:00 GMT  
 adding AND to a SQL statement
Check your single and double quotes.
Everything else seems OK.
--
HTH
Joe
Check out Dev Ashish's web site for answers to common questions
http://www.mvps.org/access/


Quote:
>     Set dBSop = CurrentDb

>     strSQLSop = "SELECT ORDER_NUMBER, CUST_ORDER_NUMBER From
> tblSALES_ORDERcopy WHERE [CUST_ORDER_NUMBER] Like '*" & Me![Warranty No] &
> "'"

>     Set rSSop = dBSop.OpenRecordset(strSQLSop, dbOpenDynaset)

> I need to add an AND statement to strSQLSop so that it searches on
> Me![AccCode] as well (this is a text field)

>     strSQLSop = "SELECT ORDER_NUMBER, CUST_ORDER_NUMBER From
> tblSALES_ORDERcopy WHERE [CUST_ORDER_NUMBER] Like '*" & Me![Warranty No] &
> "'" & " AND [CUST_REF] = '" & Me![AccCode] & "'"

> But this does not seem to work

> Any ideas?
> --
> Moiz




Thu, 16 May 2002 03:00:00 GMT  
 adding AND to a SQL statement

Quote:

> "WHERE [CUST_ORDER_NUMBER] Like '*" & Me![Warranty No] & "'" & _
> "  AND [CUST_REF] = '" & Me![AccCode] & "'"

You could try some brackets for comfort like this:

 "WHERE ([CUST_ORDER_NUMBER] Like '*" & Me![Warranty No] & "')" & _
 "  AND ([CUST_REF] = '" & Me![AccCode] & "')"

but I can't see anything actually wrong. In what way does the query
"not seem to work"?

Tim F

--



Fri, 17 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How do you add SELECT DISTINCT to sql statement?

2. Adding SQL statements using vb5

3. How to add apostrophe char in a SQL statement

4. running sql code record by record instead of statement by statement

5. Dynamic SQL Statement With SQL 6.5

6. SQL -- Needing a Hint with SQL statements.

7. SQL statement won't consistently pass from VB to SQL

8. OCX for editing SQL-Statements (SQL-Server)

9. SQL query: from SELECT statement to stored procedure with dynamic PL/SQL

10. SQL statement updateable in Acces but not SQL Server

11. Problem on SQL-Update Statement with a Data-Control in VB 5 and SQL Server 7.0

12. Write One SQL statement execute in Oracle and SQL Server

 

 
Powered by phpBB® Forum Software