* in sql instruction

G

gatarossi

Dear all,

I'm trying to do a sql instruction to bring data from access, but I don
´t know why it doesn't work:

Dim xlsht3 As Excel.Worksheet
Dim crit_customer As String

Set xlsht3 = Sheets("by model")

If xlsht3.Cells(3, 5).Value = "1-ALL CUSTOMERS" Then
crit_customer = "*"
Else
crit_customer = xlsht3.Cells(3, 5)
End If

sql = "SELECT ........ "
sql = sql & "WHERE (Left([yyyymm],4))= '2007' "
sql = sql & "AND cad_buyer_bill.buyer_name_bill Like '" &
crit_customer & "' "

When I put any customer name, it works, but when I have "1-ALL
CUSTOMERS" it doesn´t work!!!!

What can I do to solve this problem????

Thanks in advance!!!!
 
J

John Bundy

do a messagebox and see what sql is when it is processing a *. if it looks
valid, output it to a cell and copy/paste it into access and run it, this if
this doesn't pull it, it should tell you why. If it does work then i don't
have a clue.
 
G

gatarossi

Dear John,

I did it: debug.print sql

Then I put this sql code in a access consult, and for my surprise it
works!!!

I don't know why it doesn't work with excel. I think that the *
doesn't work in SELECT consult!!!

Thanks in advance!!!

André.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SQL Instruction 0
'*' in sql instruction 0
SQL instruction 1
Drop down list control value in vba 2
Bring the heading data in a sql query 0
SQL Instruction 0
Database in Excel 0
SQL - Sum Values 0

Top