(Solved) – There is a reserved word in my SQL statement


I am connecting to a database in Visual Basic. When I connect, I would like to run the following query and output the results to the spreadsheet. The query gives me expected results when I run it in Access. However I do not know how to translate the query to VB syntax.

Can anyone tell me what is wrong with this SQL statement or why I get the error message that there is a reserved word in my SQL statement?

Dim SQL As String
Dim numrows As Integer

Range("B1").Value = CustFirstName & CustLastName

SQL = "SELECT Orders.OrderDate, Sum(QuotedPrice*QuantityOrdered) AS TotalCost" _
& "FROM Orders INNER JOIN LineItems ON Orders.OrderID = LineItems.OrderID" _
& "WHERE (((Orders.customerID) = [Customer].[customerID]))" _
& "GROUP BY Orders.OrderID, Orders.OrderDate" _
& "ORDER BY Orders.OrderDate"

Leave a Reply

Your email address will not be published. Required fields are marked *