asafblasberg
Programmer
Look at the code below. I am creating a search form with textboxes. Then, the query gets created, and is added to SSQL. I'm having a problem with the AND -- where to put the AND command eg. select * from table where this = that AND ... etc. etc. --
Thanks!
AB
'Create Where Clause Based on Entries from User
Dim sSQL As String
sSQL = "Select * from quotes where "
If Me!SalesPerson <> "" Then
sSQL = sSQL & " SalesPersonName = '" & Me!SalesPerson & "'"
End If
If Me!FirstName <> "" Then
sSQL = sSQL & " FirstName LIKE '%" & Me!FirstName & "%'"
End If
If Me!LastName <> "" Then
sSQL = sSQL & "LastName LIKE '%" & Me!LastName & "%'"
End If
If Me!Company <> "" Then
sSQL = sSQL & " Company LIKE '%" & Me!Company & "%'"
End If
If Me!Phone <> "" Then
sSQL = sSQL & " Phone = '" & Me!Phone & "'"
End If
If Me!City <> "" Then
sSQL = sSQL & " City LIKE '%" & Me!City & "%'"
End If
If Me!State <> "" Then
sSQL = sSQL & " State = '%" & Me!State & "%'"
End If
If Me!Zip <> "" Then
sSQL = sSQL & " Zip = '%" & Me!Zip & "%'"
End If
If Me!Email <> "" Then
sSQL = sSQL & " Email = '" & Me!Email & "'"
End If
Me!SQLString = sSQL
Thanks!
AB
'Create Where Clause Based on Entries from User
Dim sSQL As String
sSQL = "Select * from quotes where "
If Me!SalesPerson <> "" Then
sSQL = sSQL & " SalesPersonName = '" & Me!SalesPerson & "'"
End If
If Me!FirstName <> "" Then
sSQL = sSQL & " FirstName LIKE '%" & Me!FirstName & "%'"
End If
If Me!LastName <> "" Then
sSQL = sSQL & "LastName LIKE '%" & Me!LastName & "%'"
End If
If Me!Company <> "" Then
sSQL = sSQL & " Company LIKE '%" & Me!Company & "%'"
End If
If Me!Phone <> "" Then
sSQL = sSQL & " Phone = '" & Me!Phone & "'"
End If
If Me!City <> "" Then
sSQL = sSQL & " City LIKE '%" & Me!City & "%'"
End If
If Me!State <> "" Then
sSQL = sSQL & " State = '%" & Me!State & "%'"
End If
If Me!Zip <> "" Then
sSQL = sSQL & " Zip = '%" & Me!Zip & "%'"
End If
If Me!Email <> "" Then
sSQL = sSQL & " Email = '" & Me!Email & "'"
End If
Me!SQLString = sSQL