Some time ago I took a class in Visual Basic Studio and had to construct a simple form which was linked to a database. I had a search box on the form that would filter my search results as I typed. In other words for every key stroke I made I could watch the filter working away filtering my results. This was really cool because it would give me instant feed back as I typed. If I accidentaly hit the wrong key I could would catch it immediately due to the visual feedback of seeing my filtered results go to hell. I would then back space once and then keep typing until my relsults matched what I wanted. VBA is a different story. I isn't built into VBA like it was in VB Studio. The way my form is currently set up, I have a search box that after I type in search words I have to hit enter to see the results. the search results are shown in a list box called search. I can then click on one of the items in the list and it will take me to that record and hide the list box. I want to make the search work like it did in Visual Basic Studio. As I type I want to see the list dynamically updating. Then when I see the results are sufficient, I then click on the record in the list. Way cooler and easier for the user. Here is the code I currently have. I have also attached a copy of the form and what it looks like when I enter my search. Any help would be greatly appreciated. Thanks.
Private Sub txtSearchField_AfterUpdate()
Me.Filter = "customer like '*" & Me.txtSearchField & "*'"
Me.Filter = Me.Filter & "OR desc like '*" & Me.txtSearchField & "*'"
Me.Filter = Me.Filter & "OR [partnum] like '*" & Me.txtSearchField & "*'"
Me.txtSearchField = ""
Me.blanksearch = ""
'Show the search results
Search.RowSource = "SELECT [TblOpSheetData].[ID], [TblOpSheetData].[DESC], [TblOpSheetData].[PartNum] As [PART #], [TblOpSheetData].[CUSTOMER] As [COMPANY] FROM [TblOpSheetData] " & _
"WHERE " & Me.Filter
Search.Requery
If Search.ListCount = 2 Then 'ListCount includes header row
Search.Selected(1) = True
DoCmd.GoToRecord acDataForm, Me.name, acGoTo, Search.ListIndex + 1
txtSearchField.SetFocus
ElseIf Not Search.Visible Then
Search.Visible = True
CloseSearch.Visible = True
End If
'DoEvents
End Sub
Private Sub Search_AfterUpdate()
If Search.ListIndex > -1 Then
DoCmd.GoToRecord acDataForm, Me.name, acGoTo, Search.ListIndex + 1
txtSearchField.SetFocus
Search.Visible = False
CloseSearch.Visible = False
End If
End Sub
Private Sub txtSearchField_AfterUpdate()
Me.Filter = "customer like '*" & Me.txtSearchField & "*'"
Me.Filter = Me.Filter & "OR desc like '*" & Me.txtSearchField & "*'"
Me.Filter = Me.Filter & "OR [partnum] like '*" & Me.txtSearchField & "*'"
Me.txtSearchField = ""
Me.blanksearch = ""
'Show the search results
Search.RowSource = "SELECT [TblOpSheetData].[ID], [TblOpSheetData].[DESC], [TblOpSheetData].[PartNum] As [PART #], [TblOpSheetData].[CUSTOMER] As [COMPANY] FROM [TblOpSheetData] " & _
"WHERE " & Me.Filter
Search.Requery
If Search.ListCount = 2 Then 'ListCount includes header row
Search.Selected(1) = True
DoCmd.GoToRecord acDataForm, Me.name, acGoTo, Search.ListIndex + 1
txtSearchField.SetFocus
ElseIf Not Search.Visible Then
Search.Visible = True
CloseSearch.Visible = True
End If
'DoEvents
End Sub
Private Sub Search_AfterUpdate()
If Search.ListIndex > -1 Then
DoCmd.GoToRecord acDataForm, Me.name, acGoTo, Search.ListIndex + 1
txtSearchField.SetFocus
Search.Visible = False
CloseSearch.Visible = False
End If
End Sub