Forms

3.68 Come creare un controllo di ricerca (2)
  Fedele Fabio Lopinto (Fid)
Utilizzo molto spesso il codice trovato nella Sezione Forms del SitoComune, nella FAQ di Sib intitolata Come creare un controllo di ricerca: a questo egregio sitema ho modificato qualcosina, e a mio avviso diventa ancor più utile.

Ho modificato questa parte del codice:

Private Sub Ricerca_KeyPress(KeyAscii As Integer)
   Dim rst As Recordset
   Dim str As String
   If KeyAscii = 13 Then
      If Not IsNull(Me!Ricerca.Text) Then
         Set rst = Me.RecordsetClone
         rst.FindNext "DITTA like """ & ChiaveRicerca & Me!Ricerca.Text & "*"""
         If rst.NoMatch Then rst.FindFirst "DITTA like """ & ChiaveRicerca & Me!Ricerca.Text & "*"""
         Me.Bookmark = rst.Bookmark
         rst.Close
         Set rst = Nothing
      End If
      Me!Ricerca.SetFocus
      Me!Ricerca.SelStart = 255
      KeyAscii = 0
   End If
End Sub

in questo modo:

Private Sub ricerca_KeyDown(KeyCode As Integer, Shift As Integer)
 Dim rst As Recordset
   Dim str As String
   If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
      If Not IsNull(Me!ricerca.Text) Then
         Set rst = Me.RecordsetClone
         If KeyCode = vbKeyDown Then
            rst.FindNext "Cognome like """ & Me!ricerca.Text & "*"""
             If rst.NoMatch Then
                rst.FindLast "Cognome like """ & Me!ricerca.Text & "*"""
             End If
         Else
            rst.FindPrevious "Cognome like """ & Me!ricerca.Text & "*"""
             If rst.NoMatch Then
                rst.FindFirst "Cognome like """ & Me!ricerca.Text & "*"""
             End If
         End If
         Me.Bookmark = rst.Bookmark
         rst.close
         Set rst = Nothing
      End If
      Me!ricerca.SetFocus
      Me!ricerca.SelStart = 255
   End If
End Sub

In questo modo i tasti freccia giù-freccia su si sposteranno tra i valori del controllo ricerca, dal primo all'ultimo.


Se pensate di avere del materiale freeware interessante e volete pubblicarlo, allora leggete qui.