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
| 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