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
| ' ---
' METHODE CreerFonctionRecherche
' ---
' Ecrit une fonction de recherche générique dans le
' module du formulaire de recherche.
' Cette fonction est destinée à être appelée depuis
' l'événement Après MAJ (AfterUpdate) de chaque champ critère.
'
Private Sub CreerFonctionRecherche(frm As Form, lstChampsSelectionnes As ListBox)
Dim strProg As String
Dim strLigne As String
Dim intI As Integer
Dim strChamp As String
' Construction automatique du programme VB
strProg = "Sub Recherche()" & vbCrLf & _
"Dim strFiltre As String, strSQL As String" & vbCrLf & vbCrLf & _
"strFiltre = """"" & vbCrLf
' Un filtre pour chaque champ
For intI = 0 To lstChampsSelectionnes.ListCount - 1
' Nom du champ
strChamp = lstChampsSelectionnes.ItemData(intI)
strProg = strProg & "If Not IsNull(Me![c_" & strChamp & "]) Then" & vbCrLf & _
vbTab & "If strFiltre <> """" Then strFiltre = strFiltre & "" AND """ & vbCrLf
strLigne = ConstruireCritere(strChamp)
strProg = strProg & vbTab & strLigne & vbCrLf & "End If" & vbCrLf
Next
' Application du filtre
strProg = strProg & "Me!sfmRésultat.Form.Filter= strFiltre" & _
vbCrLf & "Me!sfmRésultat.Form.FilterOn = True"
strProg = strProg & vbCrLf & "frm Test.Form.Filter= strFiltre" & _
vbCrLf & "frm Test.Form.FilterOn = True"
' Fin du programme
strProg = strProg & vbCrLf & "End Sub"
' Ajout du programme au module
' du formulaire de recherche
Dim mdl As Module
Set mdl = frm.Module
mdl.InsertText strProg
Set mdl = Nothing
End Sub |
Partager