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
|
Private Sub cmd_recherche_Click()
Dim strTable As String, strField As String, strCriteria As Sting, strSql As String
Dim Criter As Variant
strTable = Me.cbo_table 'récupérer le nom de la table
strField = Me.cbo_champ 'récupérer le nom du champ
If IsNull(strTable) Or IsNull(strField) Then ' l'une des listes est vide
MsgBox "Vous devez sélectionner une table et un champ.", vbExclamation + vbOKOnly, "une erreur"
Exit Sub
End If
'Composer le critere de recherche
strCriteria = strTable & "." & strField & " Like ""*" & Me.txt_critere & "*"""
'Construire la requête sql de séléction des données
strSql = " SELECT DISTINCTROW " & strTable & ".*"
strSql = strSql & "INTO tableRecherche "
strSql = strSql & "FORM " & strTable
strSql = strSql & "WHERE (( " & strCriteria & "));"
DoCmd.RunSQL strSQL
Me.lst_resultat.RowSource = strSql
Me.lst_resultat.Requery
If (Me.lst_Recherche.ListCount = 0) Then 'le critère de recherche est faux ou inexistant
MsgBox "votre critère de recherche n'existe pas ou vous devez en spécifier un"
Exit Sub
End If
End Sub |
Partager