Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
On Error Resume Next
Dim LengthText As Integer
Dim NewText As Integer
Dim Answer As String
Dim LeftText As String
‘Get the length of the typed text.
LengthText = Len(Text1)
‘Handle Backspace and Delete keys.

If KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Then
Exit Sub
Else
‘Set variable to the typed text.
LeftText = Text1
‘Query database for items in desired
‘field that begin with your typed charac
‘     ters.
Data1.RecordSource = “Select [Your Field] From ” & _
“[Your Database Table] ” & _
“Where [Your Field] Like ‘” & LeftText & “*’”
Data1.Refresh
‘If no match, leave blank.

If LeftText = “” Then
Answer = “”
Else
‘If match, set variable to result.
Answer = Data1.Recordset.Fields(“Your Field”)
End If
‘Get length of result.
NewText = Len(Answer)
‘If no match, fill Text box with
‘typed characters only.

If NewText = 0 Then
Text1 = LeftText
Else
‘If query returns result,
‘fill Text box with result.
Text1 = Answer
‘Set cursor to end of typed characters
Text1.SelStart = LengthText
‘Select and highlight portion of
‘result text that wasn’t typed.
Text1.SelLength = Len(Answer) – LengthText
End If
‘Close connection so you can
‘connect to another text box.
Data1.Recordset.Close
End If
End Sub


Vota este artículo:
1 Estrella2 Estrellas3 Estrellas4 Estrellas5 Estrellas (No Ratings Yet)
Loading ... Loading ...

Posts anterior y posterior:


Posts Relacionados: