I am a volunteer at a retirement center and helped design a kiosk which visitors use to find the room number and telephone number of a resident. We are using a touch screen monitor and a virtual keyboard. Currently the user types the first letter of the resident’s last name and the list box scrolls and highlights the first alphabetical name that starts with that letter. The user then scrolls to find the information of the resident they are looking for. We are trying to modify the application to allow the user to type in the first few letters on the resident’s last name. I found an application on the internet that nearly does what we want, except it does not highlight a name as it scrolls and if the user types a letter that no resident’s name begins with the list box goes blank and there is no way to get the list box contents back. I added a text box and a command button to my original application. Here is the code I have tried as I have adapted it.
Option Compare Database
Option Explicit
Private blnSpace As Boolean
Private Sub Ctl_cmdNewSearch_Click()
Me.txtSearch.Value = ""
Me.txtSearch.SetFocus
Me.Requery.List0
End Sub
Private Sub txtSearch_Change()
'CODE THAT HANDLES WHAT HAPPENS WHEN THE USER TYPES IN THE SEARCH BOX
Dim strFullList As String
Dim strFilteredList As String
10 If blnSpace = False Then
20 Me.Refresh 'refresh to make sure the text box changes are actually available to use
'specify the default/full rowsource for the control
30 strFullList = "SELECT res_last_name, res_first_name, res_middle_name, spell_build, curr_room_nbr, curr_bed, phone FROM qryKiosk ORDER BY [res_last_name]; "
'specify the way you want the rowsource to be filtered based on the user's entry
40 strFilteredList = "SELECT res_last_name, res_first_name, res_middle_name, spell_build, curr_room_nbr, curr_bed FROM qryKiosk WHERE [res_last_name] LIKE ""*" & Me.txtSearch.Value & _
"*"" ORDER BY [res_last_name]"
'run the search
50 fLiveSearch Me.txtSearch, Me.List0, strFullList, strFilteredList
60 End If
End Sub
Private Sub txtSearch_KeyPress(KeyAscii As Integer)
'NECESSARY TO IDENTIFY IF THE USER IS HITTING THE SPACEBAR
'IN WHICH CASE WE WANT TO IGNORE THE INPUT
10 On Error GoTo err_handle
20 If KeyAscii = 32 Then
30 blnSpace = True
40 Else
50 blnSpace = False
60 End If
Exit Sub
err_handle:
80 Select Case Err.Number
Case Else
90 MsgBox "An unexpected error has occurred: " & vbCrLf & Err.Description & _
vbCrLf & "Error " & Err.Number & "(" & Erl & ")"
100 End Select
End Sub
When I type into the text box txtSearch I get the message:
“Error accessing file. Network connection may have been lost”
Then the debugger highlights the line:
Private Sub txtSearch_Change()
Or the line:
Private Sub txtSearch_KeyPress(KeyAscii As Integer)
Also, the cmdNewSearch button does not erase the contents of txtSearch nor does it put focus there.
For some reason the code generator automatically put Ctl in front of cmdNewSearch line
Private Sub Ctl_cmdNewSearch_Click()