Autocomplete problem

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?

SURESH MENON
01-09-2004, 10:16 PM
it's becasuse

Do While Not rstObj.EOF

Dennis DVR
01-10-2004, 11:34 AM
you will need to store the bookmark to a variable and use the move method of the recordset using the variable as parameter i.e


Declare a varianle name vBookMark at the top of your form code
Dim vBookMark As Long
rstObj.Move vBookmark + 1, 1
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))
vBookMark = rstObjt.BookMark
Exit Do
End If


btw why do you want to use the do loop intead of select statement?

ncozzolino
01-12-2004, 05:55 AM
you will need to store the bookmark to a variable and use the move method of the recordset using the variable as parameter i.e


Declare a varianle name vBookMark at the top of your form code
Dim vBookMark As Long
rstObj.Move vBookmark + 1, 1
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))
vBookMark = rstObjt.BookMark
Exit Do
End If


btw why do you want to use the do loop intead of select statement?

I'm not really sure what I'm doing. How would I do it in a select statement?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum