1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| Option Compare Database
Private Sub cbo_champ_AfterUpdate()
Forms!Recherche!txt_critere.SetFocus
End Sub
Private Sub Form_Load()
KeyPreview = True
End Sub
Private Sub txt_critere_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then Call cmd_recherche_Click
End Sub
Private Sub cbo_table_AfterUpdate()
Me.cbo_champ.RowSource = Me.cbo_table.Value
Me.cbo_champ.Requery
End Sub
Private Sub cmd_recherche_Click()
Dim strTable As String, strField As String, strCriteria As String, strSql As String
Dim Criter As Variant
If IsNull(Me.cbo_table) Or IsNull(Me.cbo_champ) Then
MsgBox "Vous devez renseigner la table et le champ pour effectuer une recherche !", vbExclamation + vbOKOnly, "Recherche"
Exit Sub
End If
strTable = "[" & Me.cbo_table & "]" ' recupère le nom de la table
strField = "[" & Me.cbo_champ & "]" ' recupère le nom du champ
Select Case Me.opt_recherche
Case 1 ' strictement egal
strCriteria = strTable & "." & strField & " Like """ & Me.txt_critere & """"
Case 2 ' commence par
strCriteria = strTable & "." & strField & " Like """ & Me.txt_critere & "*"""
Case 3 ' contient
strCriteria = strTable & "." & strField & " Like ""*" & Me.txt_critere & "*"""
Case 4 ' fini par
strCriteria = strTable & "." & strField & " Like ""*" & Me.txt_critere & """"
Case 5 ' ne contient pas
strCriteria = "NOT (" & strTable & "." & strField & " Like ""*" & Me.txt_critere & "*"") "
End Select
' construit la requête sql
strSql = "SELECT DISTINCTROW " & strTable & ".*"
strSql = strSql & " FROM " & strTable
strSql = strSql & " WHERE ((" & strCriteria & "));"
Me.lst_resultat.RowSource = strSql ' affecte sql a lst_Resultat
Me.lst_resultat.Requery ' recalcule la liste
Forms!Recherche!txt_critere = ""
Forms!Recherche!txt_critere.SetFocus
End Sub |
Partager