Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL in VBA Help 1

Status
Not open for further replies.

3239

Technical User
May 14, 2003
64
No matter how much I try to correct the syntax of my VBA sql statements, I always get errors every time. Does anyone know where I can find tutorials explaining the syntax of sql statements in VBA? It's like hit or miss with me. Sometimes I get the syntax right. Most of the time I don't.

The erroneous code is below.

Thanks for your help.

Code:
docmd.RunSQL "SELECT Format([CSOrderID],"\A0000") AS Requisition, " & _
"Suppliers.SupplierName, Employees.EmployeeID," & _
"Employees.FirstName & " " & [LastName] AS Name," & _
"DepartmentInfo.Center, DepartmentInfo.Department, DepartmentInfo.Address, " & _
"DepartmentInfo.City, DepartmentInfo.State, DepartmentInfo.ZipCode," & _
"Suppliers.Address, Suppliers.City, Suppliers.PostalCode, Suppliers.StateOrProvince, " & _
"CS_REQ.OrderDate, CS_REQ.CSComments " & _
"FROM (Employees INNER JOIN DepartmentInfo ON Employees.EmployeeID = " & _
"DepartmentInfo.EmployeeID) " & _
"INNER JOIN (Suppliers INNER JOIN CS_REQ ON Suppliers.SupplierID = " & _
"CS_REQ.SupplierID) ON DepartmentInfo.EmployeeID = " & _
"CS_REQ.EmployeeID " & _
"IN '\\Svr-fp-rh3\groups\Purchasing Tracking Database Systems\Administration\Purchase Tracking System Admin_be.mdb' " & _
"WHERE (((Format([CSOrderID], "A0000")) Like "*" & [Forms]![POCreator]![POID] & "*")) " & _
"ORDER BY Format([CSOrderID],"A0000"); "
 
Tip: use single quotes for SQL literal strings, eg:
Code:
"SELECT Format([CSOrderID],[!]'[/!]\A0000[!]'[/!]) AS Requisition, " & _

Furthermore, the DoCmd.RunSQL method is for ACTION queries ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PHV. That was very helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top