Hi, I only joined yesterday. I have a problem with the following code where I get a missing operator error. Could someone please tell me what I am doing wrong.

' Function: strbuildSQLstr
' Purpose: Build SQL String to retrieve ADO Recordset
' Paramters: strChoice- string(Good or Bad),strStart- string(start date)
' strEnd - string( End Date)
' Returns: String - SQL Statement build with parameters passed
Function strbuildSQLstr(strChoice As String) As String
Dim strtemp As String

strtemp = "Select * from SizeRange Where Style =" & "'" & txtStyle & "'"
If strChoice > "" Then strtemp = strtemp & "'" & " and WHERE type =" & "'" & strChoice & "'"

' return the SQL String
strbuildSQLstr = strtemp & " " & "ORDER by Date"

please change the order by field name. Date is not a recomended field name in database as it is a predefined data type.


Once already Where is given in the first statement, after that use only "And"

Change the second line to :

If Trim(strChoice) <> "" Then 
    strtemp = strtemp & " and type ='" & strChoice & "' "
End If


Thanks for your help. Is it the fact I am using 'Date' as a field name or actually ordering by date that is a problem?

Think it is working now anayway.

This article has been dead for over six months. Start a new discussion instead.