G
Guest
fm_Main
txtFind
fs_SubForm (Datasheet - not linked to main form)
Displays a list of Australian Postal Codes, States & Localities (Suburbs)
As you type in the txtFind textbox, the list of matching Postal Localities
reduces.
I was having trouble dealing with the backspace key which now works with the
code shown below.
I was wondering if anyone could come up with a more elegant way to achieve
this.
fm_Main Code Sample (no code in fs_SubForm)
Option Compare Database
Option Explicit
Private msWhereCrit As String
Private Sub txtFind_KeyUp(KeyCode As Integer, Shift As Integer)
Dim sSQL As String
sSQL = "SELECT Locality, State, PCode, Category FROM PCodes " & _
"WHERE Locality like('*" & msWhereCrit & "*');"
txtFind = msWhereCrit
txtFind.SetFocus
txtFind.SelStart = Len(msWhereCrit)
fs_SubForm.Form.RecordSource = sSQL
fs_SubForm.Form.Requery
End Sub
Private Sub txtFind_KeyPress(KeyAscii As Integer)
Dim sSQL As String
Dim sKey As String
Select Case KeyAscii
Case 8
If txtFind = "" Then
Exit Sub
Else
msWhereCrit = Left$(txtFind, Len(txtFind) - 1)
KeyAscii = 0
End If
Case 32 To 126
sKey = Chr$(KeyAscii)
KeyAscii = 0
msWhereCrit = msWhereCrit & sKey
Case 127
' do nothing
Exit Sub
Case Else
KeyAscii = 0
Exit Sub
End Select
End Sub
txtFind
fs_SubForm (Datasheet - not linked to main form)
Displays a list of Australian Postal Codes, States & Localities (Suburbs)
As you type in the txtFind textbox, the list of matching Postal Localities
reduces.
I was having trouble dealing with the backspace key which now works with the
code shown below.
I was wondering if anyone could come up with a more elegant way to achieve
this.
fm_Main Code Sample (no code in fs_SubForm)
Option Compare Database
Option Explicit
Private msWhereCrit As String
Private Sub txtFind_KeyUp(KeyCode As Integer, Shift As Integer)
Dim sSQL As String
sSQL = "SELECT Locality, State, PCode, Category FROM PCodes " & _
"WHERE Locality like('*" & msWhereCrit & "*');"
txtFind = msWhereCrit
txtFind.SetFocus
txtFind.SelStart = Len(msWhereCrit)
fs_SubForm.Form.RecordSource = sSQL
fs_SubForm.Form.Requery
End Sub
Private Sub txtFind_KeyPress(KeyAscii As Integer)
Dim sSQL As String
Dim sKey As String
Select Case KeyAscii
Case 8
If txtFind = "" Then
Exit Sub
Else
msWhereCrit = Left$(txtFind, Len(txtFind) - 1)
KeyAscii = 0
End If
Case 32 To 126
sKey = Chr$(KeyAscii)
KeyAscii = 0
msWhereCrit = msWhereCrit & sKey
Case 127
' do nothing
Exit Sub
Case Else
KeyAscii = 0
Exit Sub
End Select
End Sub