Una famiglia di sistemi di gestione per database relazionali di Microsoft progettati per semplificare l'uso.
ciao Peppino38,
interessante 3d, non ci avevo mai pensato...!
la combobox gestisce la cosa in modo nativo e più facilmente, con la textBox è necessario lavorarci un po' su.
Secondo me per simulare l'autoFill (o meglio autoExpand o espansione automatica) della comboBox, devi tenere conto di quello che viene digitato volta per volta, tasti backspace, canc e apostrofi compresi e per permettere di continuare la digitazione controllare la parte selezionata e relativa lunghezza con le proprietà selText e selLength, aprendo un recordset per verificare se quanto digitato "matcha" oppure no...
esempio :
Option Compare Database
Option Explicit
Private strSqlSel As String
Private intChar As Integer
Private strString As String
Private Const strSqlFull As String = "SELECT comuni.citta FROM comuni"
Private Sub citta_Change()
Dim rst As DAO.Recordset
strSqlSel = strSqlFull & " WHERE comuni.citta Like '" & Replace(strString, "'", "''") & "*' ORDER BY comuni.citta"
Set rst = DBEngine(0)(0).OpenRecordset(strSqlSel, dbOpenDynaset)
With Me.citta
If intChar <> 8 And intChar <> 46 Then
.Value = strString
.SelStart = Len(.Value)
With rst
.FindFirst "[citta] like '" & Replace(strString, "'", "''") & "*'"
If Not .NoMatch Then
Me.citta = rst.Fields(0)
End If
End With
.SelStart = Len(strString)
.SelLength = Len(.Value) - Len(strString)
End If
End With
Set rst = Nothing
End Sub
Private Sub citta_KeyDown(KeyCode As Integer, Shift As Integer)
intChar = KeyCode ' gestione canc
End Sub
Private Sub citta_KeyPress(KeyAscii As Integer)
intChar = KeyAscii
Select Case intChar
Case 65 To 90, 97 To 122, 32, 39 ' alfabeto ad A...Z e da a...z 32=space , 39='
strString = strString & Chr(intChar)
Case 8 ' 8=backspace
If Len(Me.citta.Text) > 0 Then
With Me.citta
strString = Left$(.Text, Len(.Text) - 1)
End With
End If
End Select
End Sub
Private Sub Form_Current()
If Me.NewRecord Then strString = vbNullString
End Sub
se la textBox interessata da questo "caratteristica" è una sola può andare anche così, fossero una per maschera o più per maschera, andrebbe ripensato il tutto con una classe specifica.
Sempre IMHO.
prova a vedere qui se ci siamo.
Facci sapere.
Ciao, Sandro.