VB Otomatik Tamamlama Veritabanina veri kaydederken Form textbox'larina ilk harfleri girildiginde veritabanindan benzer sonuçlari bularak otomatik olarak tamamlayan kisa bir kod:
Dim ad as string
Private Sub text1_KeyPress(KeyAscii As Integer)
On Error GoTo hata
Select Case KeyAscii
Case Is = 13
KeyAscii = 0
ad = ""
text2.SetFocus 'diger textbox'a geçis
Case Is = 8
ad = Left(ad, Len(ad) - 1) 'backspace tusu
GoTo arabul
Case Else
ad = ad & Chr(KeyAscii)
arabul:
KeyAscii = 0
rst.Open "SELECT * FROM Personeltablosu WHERE AdiSoyadi LIKE '" & ad & "%" & "' " 'recordset ve baglanti önceden tanimlanmis
text1= rst!AdiSoyadi
text1.SelStart = Len(ad)
text1.SelLength = Len(text1) - Len(ad)
hata:
If Err.Number = 3021 Then
Err.Clear
MsgBox "Adi " & """" & ad & """" & " ile baslayan personel yok !...", vbCritical, "HATA"
ad = Mid(ad, 1, Len(ad) - 1)
End If
rst.Close
End Select
End Sub |