Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

creation d'un filtre sur une liste a choix multiples applicable à un etat

Aucune réponse
Avatar
abaline
Bonjour,
Je souhaite utiliser les choix fait dans une liste ( de pays par exemple) pour générer un état, en effet celui-ci me renvoi systématiquement un etat pour toutes les données,
je pensai donc utilisé un filtre, mais je dois reconnaitre avoir de bien piètre compétence en VBA, j'apprends un peu sur le tas la ..
voici le code :

Private Sub Command18_Click()
On Error GoTo Err_Command18_Click

Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean

Dim MyDB As DAO.Database
Dim qdef As DAO.QueryDef
Dim i As Integer
Dim strSQL As String
Dim strWhere As String
Dim strIN As String
Dim flgSelectAll As Boolean
Dim varItem As Variant

Dim inti As Integer
Dim dblPct As Double
Dim frm As Form

Set MyDB = CurrentDb()

strSQL = "SELECT t1.Country FROM Tbl_country t1"

'Build the IN string by looping through the listbox
For i = 0 To Liste13.ListCount - 1
If Liste13.Selected(i) Then
If Liste13.Column(0, i) = "All" Then
flgSelectAll = True
End If
strIN = strIN & "" & Liste13.Column(0, i) & ","
End If
Next i



'Create the WHERE string, and strip off the last comma of the IN string
strWhere = " And [t1.No_id] in (" & Left(strIN, Len(strIN) - 1) & ") order by t1.country, t2.d_year desc"

'If "All" was selected in the listbox, don't add the WHERE condition
If Not flgSelectAll Then
strSQL = strSQL & strWhere
' DoCmd.OpenReport "country_report", acViewPreview, Forms!Formreportcountry!Liste13 = strSQL

End If
MyDB.QueryDefs.Delete "Qry_Report"
Set qdef = MyDB.CreateQueryDef("Qry_Report", strSQL)

'Open the query, built using the IN clause to set the criteria


DoCmd.OpenReport "Country_report", acViewPreview, , , strSQL

'Clear listbox selection after running query
For Each varItem In Me.Liste13.ItemsSelected
Me.Liste13.Selected(varItem) = False
Next varItem




Exit_Command18_Click:
Exit Sub

Err_Command18_Click:

If Err.Number = 5 Then
MsgBox "You must make a selection(s) from the list" _
, , "Selection Required !"
Resume Exit_Command18_Click
Else
'Write out the error and exit the sub
MsgBox Err.Description
Resume Exit_Command18_Click
End If
End Sub


ayant remanié le code maintes fois, il est possible qu'il y ait des choses inutiles ..
pouvez vous m'aider a résoudre ce problème ? ( en résumé n'afficher des états que pour les pays sélectionnés dans ma liste)

merci

Réponses