ncozzolino
01-09-2004, 04:59 PM
Here is my code:
Private Sub dcmb_employee_KeyUp(KeyCode As Integer, Shift As Integer)
Dim txtLen As String
Dim mText As String
With dcmb_employee
txtLen = Len(.Text)
Select Case KeyCode
Case vbKeyDelete 'trap these keys to not perform search
Case vbKeyBack
Case vbKeySpace
Case Else
rstObj.MoveFirst
Do While Not rstObj.EOF
If Option2(0) = True Then
If Trim(UCase(Left(rstObj!cltname, txtLen))) = Trim(UCase(.Text)) And Trim(.Text) <> "" Then
.Text = rstObj!cltname & " "
.SelStart = txtLen
.SelLength = Len(.Text) - Len(Trim(txtLen))
Exit Do
End If
Else
If Trim(UCase(Left(rstObj!cltnum, txtLen))) = Trim(UCase(.Text)) And Trim(.Text) <> "" Then
.Text = rstObj!cltnum & " "
.SelStart = txtLen
.SelLength = Len(.Text) - Len(Trim(txtLen))
Exit Do
End If
End If
rstObj.MoveNext
Loop
End Select
End With
End Sub
The code works but it searches through all 1100 entries everytime I enter a character. Meaning, if I type 27191 it searches from top to bottom with every character. How to make it search from the last located character?
Private Sub dcmb_employee_KeyUp(KeyCode As Integer, Shift As Integer)
Dim txtLen As String
Dim mText As String
With dcmb_employee
txtLen = Len(.Text)
Select Case KeyCode
Case vbKeyDelete 'trap these keys to not perform search
Case vbKeyBack
Case vbKeySpace
Case Else
rstObj.MoveFirst
Do While Not rstObj.EOF
If Option2(0) = True Then
If Trim(UCase(Left(rstObj!cltname, txtLen))) = Trim(UCase(.Text)) And Trim(.Text) <> "" Then
.Text = rstObj!cltname & " "
.SelStart = txtLen
.SelLength = Len(.Text) - Len(Trim(txtLen))
Exit Do
End If
Else
If Trim(UCase(Left(rstObj!cltnum, txtLen))) = Trim(UCase(.Text)) And Trim(.Text) <> "" Then
.Text = rstObj!cltnum & " "
.SelStart = txtLen
.SelLength = Len(.Text) - Len(Trim(txtLen))
Exit Do
End If
End If
rstObj.MoveNext
Loop
End Select
End With
End Sub
The code works but it searches through all 1100 entries everytime I enter a character. Meaning, if I type 27191 it searches from top to bottom with every character. How to make it search from the last located character?