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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
Private Sub BTN_LISTING2018_Click()
Dim strChoixMotif As String
Dim strChoixSillon As String
Dim strChoixCanal As String
Dim varItm As Variant
Dim strSql As String
' Contrôle de saisie : MOTIF
If IsNull(Me.ChoixMotif) Then
MsgBox "Veuillez sélectionner un motif", vbCritical + vbOKOnly
Me.ChoixMotif.SetFocus
Exit Sub
End If
' Contrôle de saisie : Date début
If IsNull(Me.DateDebut) Then
MsgBox "Veuillez saisir une date de début", vbCritical + vbOKOnly
Me.DateDebut.SetFocus
Exit Sub
End If
' Contrôle de saisie : Date fin
If IsNull(Me.DateFin) Then
MsgBox "Veuillez saisir une date de fin", vbCritical + vbOKOnly
Me.DateFin.SetFocus
Exit Sub
End If
strChoixMotif = """" & Me.[ChoixMotif] & """"
' Construction de la liste "IN" à partir d'une zone de liste
If Me.ChoixSillon.ItemsSelected.Count > 0 Then
With Me.[ChoixSillon]
For Each varItm In .ItemsSelected
strChoixSillon = strChoixSillon & IIf(strChoixSillon = "", """", ",""") & (.ItemData(varItm)) & """"
Next varItm
strChoixSillon = " In(" & strChoixSillon & ")"
End With
Else ' Prendre tous si aucun choix
strChoixSillon = " Like ""*"""
End If
If Me.ChoixCanal.ItemsSelected.Count <> 0 Then
With Me.[ChoixCanal]
For Each varItm In .ItemsSelected
strChoixCanal = strChoixCanal & IIf(strChoixCanal = "", """", ",""") & (.ItemData(varItm)) & """"
Next varItm
strChoixCanal = " In(" & strChoixCanal & ")"
End With
Else ' Prendre tous si aucun choix
strChoixCanal = " Like ""*"""
End If
' Fabrication de l'instruction SQL
strSql = "SELECT CODE,[DATE],CANAL,SILLON,MOTIF,MOTIF_LONG,VERBE" & _
" FROM [Gestion_2018]" & _
" WHERE [DATE] Between #" & Format(Me.[DateDebut], "mm/dd/yyyy") & "# And #" & Format(Me.[DateFin], "mm/dd/yyyy") & "#" & _
" AND MOTIF Like " & strChoixMotif & _
" AND SILLON" & strChoixSillon & _
" AND CANAL" & strChoixCanal & ";"
' Affecter la sélection au recordsource du sous-formulaire
Me.frm_Liste_Selection.Form.RecordSource = strSql
' Afficher le sous-formulaire s'il y a des données
If Me.frm_Liste_Selection.Form.Recordset.RecordCount > 0 Then
Me.frm_Liste_Selection.Visible = True
Me.ÉtiqSF.Caption = "Résultat de la sélection"
Me.ÉtiqSF.Visible = True
Else ' Cacher le sous-formulaire si pas de données
Me.frm_Liste_Selection.Visible = False
Me.ÉtiqSF.Caption = "Aucun résultat trouvé"
Me.ÉtiqSF.Visible = True
End If
End Sub
Private Sub Form_Load()
'cacher le sous-formulaire à l'ouverture
Me.frm_Liste_Selection.Visible = False
Me.ÉtiqSF.Visible = False
End Sub |
Partager