Problème de fonction "Filter" avec Array VBA

Résolu
panda -  
Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

j'ai le code suivant pour vérifier que ma variable "nomod" appartient a l'ensemble (8,9,...):

Dim nomod As String
Dim firstarray As Variant, myarray As Variant

firstarray = Array(8, 9, 10, 11, 12, 13, 14, 15)
myarray = Filter(firstarray, nomod)
If UBound(myarray) > -1 Then

l'instruction "myarray = Filter(firstarray, nomod)" renvoie toujours le même message d'erreur: "erreur de compilation : nombre d'arguments incorrect ou affectation de propriété incorrecte"

je suis sous Access 2010. avez vous une idée de ce qui coince?

2 réponses

  1. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
     
    Bonjour,

    votre code est pour du VBA excel, ne fonctionne pas sous access.
    Sous access Filter: form.Filter est utilisee pour un formulaire

    code pour recherche dans tableau:
    Sub test()
        Dim nomod As String
        Dim firstarray As Variant, myarray As Variant
        Dim Trouve As Boolean
    
        nomod = 25
    
        firstarray = Array(8, 9, 10, 11, 12, 13, 14, 15)
    
        For Each myarray In firstarray
            If nomod = myarray Then
                Trouve = True
                Exit For
            End If
        Next myarray
        
        If Trouve Then
            MsgBox "ok"
        Else
            MsgBox "Pas trouvé"
        End If
    End Sub


    A+
    0
    1. Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   1 784
       
      Bonjour f894009

      La fonction Filter n'est pas une fonction Excel, c'est une fonction VBA.Strings

      Pour l'utiliser sous Access il faut employer la syntaxe complète :
      myarray = VBA.Strings.Filter(firstarray, nomod)

      Cordialement
      Patrice
      0