-
I am want to use a Input box to set the WHERE clause in a SQL statement I tried using for example:
strSQL="SELECT * from SHAPES WHERE color =Search$" but it will not recognise the value in Search$ is this possible or is there any easier way to do this .When I run in debug mode the Search$ contains the value I want but not when I add it to the sql
Mike
-
You have the right " in the wrong spot.
try this:
strSQL="SELECT * from SHAPES WHERE color = '" & Search$ & "'"
You will also need the ' before and after your variable if it is a string.
-
You can do any string formatting you like, eg sometimes you don't want a WHERE statement at all so...
Code:
Dim SQLStr as String
Dim WhereStr as String
If cboBox.text = "Sydney" then
WhereStr = " where city = 'Sydney'"
ElseIf cboBox.text = "New York" then
WhereStr = " where city = 'New York'"
Else
WhereStr = ""
End If
SQLStr = "Select * from MyDB(Nolock)" & WhereStr