Reputation: 3
My knowledge in Visual Basic 6 is basic. What is wrong with this code? And what would be a little tutorial if possible?
SQL = "SELECT * FROM tblEmployee WHERE " & "JOB" & " like '" & searchkey & "%'" And "CloseJob" & " like '" & "NO" & "%'"
I tried searching for it, but I can't find any Visual Basic 6 code for multiple criteria. Or I'm just terrible in searching, hehe.
The original code was
SQL = "SELECT * FROM tblEmployee WHERE " & "JOB" & " like '" & searchkey & "%'"
so I thought by adding AND
at the end, and make another criteria would solve the problem.
Upvotes: 0
Views: 9268
Reputation: 2230
Well, you could do something as below, where you would replace with the column name and the variable name, respectively. This gets anything like somethingElse with a wildcard on both ends.
SQL = "SELECT * FROM tblEmployee WHERE JOB LIKE '" & searchkey & "%' AND CloseJob LIKE 'NO%'"
Upvotes: 0
Reputation: 16368
Your AND
needs to be inside the quotes:
SQL = "SELECT * FROM tblEmployee WHERE " & _
"JOB like '" & searchkey & "%' And CloseJob like 'NO%'"
Basically, all this line is doing is concatenating strings, and in this case, the only variable that needs to be inserted into the concatenated string is searchkey
.
On a side note, I added the vb6 line continuation: & _
for readability.
Upvotes: 2