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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error 3138- Syntax error in ORDER BY clause

Status
Not open for further replies.

liltechy

Programmer
May 17, 2002
145
0
0
US
I have a combo box that on my main form that I want to refresh my subform, when I select my Vendor I get this error msg "Run-time error 3138- Syntax error in ORDER BY clause" and I don't understand why. Below is my code.

Dim strSQL As String
Dim strSQLSF As String

strSQLSF = " SELECT * FROM qryafehdr2 "
strSQLSF = strSQLSF & " WHERE qryafehdr2.Internal Order Number = " & Me.List20 & " And "
strSQLSF = strSQLSF & " qryafehdr2.VendorName = '" & List21 & "'"


Forms![Executive Look-Up Form]![Invoice_Header_Total_Exec subform1].LinkChildFields = ""
Forms![Executive Look-Up Form]![Invoice_Header_Total_Exec subform1].LinkMasterFields = ""

Forms![Executive Look-Up Form]![Invoice_Header_Total_Exec subform1].LinkChildFields = "Internal Order Number;VendorName"
Forms![Executive Look-Up Form]![Invoice_Header_Total_Exec subform1].LinkMasterFields = "Internal Order Number;VendorName"
Me.RecordSource = strSQLSF
Me.Requery
 
Try using brackets around field names that include spaces.
that is:
Internal Order Number should be [Internal Order Number]
 
I put the brackets and I am still getting the same error.


liltechy
 
Hmmm. I assumed the field name "Internal Order Number" was being read as "Internal". Are you sure you changed the reference in your strSQLSF variable to include brackets?

Code:
 strSQLSF = "SELECT * FROM qryafehdr2" & _
     " WHERE qryafehdr2.[Internal Order Number] = " & Me.List20 & _
     " AND qryafehdr2.VendorName = '" & me.List21 & "'"

 
I did include the brackets in my strSQLSF reference and I still get the same error.

liltechy
 
oooh, hey wait. You are basing the SELECT query on a Query? What SQL are you using for qryafehdr2?
 
I don't understand your question.


litechy
 
Your SQL says
Code:
SELECT * FROM qryafehdr2...
I assume qryafehdr2 is a query and I'm wondering if thats the culprit. So does that query stand on its own? What is it's SQL?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top