* in sql instruction

  • Thread starter Thread starter gatarossi
  • Start date Start date
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!!!!
 
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.
 
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é.
 
Back
Top