I have a search form that searches for the criteria selected. I'm want to get the search method to look into multiple textboxes instead of just one. Please help I'm fairly new to Access/VBA. My code is the following but it does not work when a certain tool which is in [tool2] or {tool3] etc. It just seems like it only looks at [tool1] and if it does not find it there it just stops there.
[CODE=vb]Private Sub cmdFind_Click()
Dim varwhere As Variant
Dim rst As DAO.Recordset
'Initialize to Null
varwhere = Null
If IsNull(Me![Keyword]) Or (Me![Keyword]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criteria!"
Me![Keyword].SetFocus
Exit Sub
End If
If SortBy = "Tools" Then
varwhere = (varwhere + " AND ") & "[tools1] & [tool2] & [tool3] LIKE '" & Me.Keyword & "*'"
Set rst = DBEngine(0)(0). OpenRecordset(" SELECT * FROM customers WHERE " & varwhere)
If rst.RecordCount = 0 Then
Set rst = DBEngine(0)(0). OpenRecordset(" SELECT * FROM customers WHERE " & varwhere)
MsgBox "No Access Card Found.", vbInformation, gstrAppTitle
rst.Close
Set rst = Nothing
Exit Sub
End If
rst.MoveLast
DoCmd.OpenForm "searchresults" , WhereCondition: =varwhere
Forms!Searchres ults.SetFocus
DoCmd.Close acForm, Me.Name
'Clean up recordset
rst.Close
Set rst = Nothing
Exit Sub
End If[/CODE]
[CODE=vb]Private Sub cmdFind_Click()
Dim varwhere As Variant
Dim rst As DAO.Recordset
'Initialize to Null
varwhere = Null
If IsNull(Me![Keyword]) Or (Me![Keyword]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criteria!"
Me![Keyword].SetFocus
Exit Sub
End If
If SortBy = "Tools" Then
varwhere = (varwhere + " AND ") & "[tools1] & [tool2] & [tool3] LIKE '" & Me.Keyword & "*'"
Set rst = DBEngine(0)(0). OpenRecordset(" SELECT * FROM customers WHERE " & varwhere)
If rst.RecordCount = 0 Then
Set rst = DBEngine(0)(0). OpenRecordset(" SELECT * FROM customers WHERE " & varwhere)
MsgBox "No Access Card Found.", vbInformation, gstrAppTitle
rst.Close
Set rst = Nothing
Exit Sub
End If
rst.MoveLast
DoCmd.OpenForm "searchresults" , WhereCondition: =varwhere
Forms!Searchres ults.SetFocus
DoCmd.Close acForm, Me.Name
'Clean up recordset
rst.Close
Set rst = Nothing
Exit Sub
End If[/CODE]
Comment