Variables in docmd.runsql command

  • Thread starter Thread starter David
  • Start date Start date
D

David

Here is my command I'm trying to run.

DoCmd.RunSQL ("UPDATE OrderEntry LEFT JOIN Tickets ON OrderEntry.ORDERNUMBER
= Tickets.OrderNumber SET Tickets.InvoiceNumber =
DMax('INVOICENUMBER','INVOICES'), Tickets.Invoiced = Yes WHERE
(((Tickets.Invoiced)= No) And ((OrderEntry.CUSTOMERCODE)= rsCustomerCode)
And ((OrderEntry.SHIPTO) = rsAddress) And ((Tickets.Delivered) = Yes) And
((Tickets.Cancelled) = No)) Or (((Tickets.Invoiced) = No) And
((OrderEntry.CUSTOMERCODE) = rsCustomerCode) And ((OrderEntry.SHIPFROM) =
rsAddress) And ((Tickets.Delivered) = Yes) And ((Tickets.Cancelled) = No))")

The variables are
rscustomercode
rsaddress
rsmaterial

I tested these variables and they do contain the required data. For some
reason when I run the command it prompts for me to fill in the variable
data. I'm sure its a syntax error. What am I doing wrong?

Thanks,

Dave
 
David

Move the variables out of the SQL syntax and concatenate them like this:
"And ((OrderEntry.CUSTOMERCODE)=" & rsCustomerCode & ") "

Make sure you include single quotes around text and #'s around dates.
"And MyDate=#" & rsDate & "#)"
 

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

Back
Top