RechercheV

Bonjour

voila j'ai un problème que je n’arrive pas à résoudre malgré es visite sur des tutos

j'ai un formulaire userform rechercheV mes un erreur 13 execution si quelqu'un pourrait me donner

un coup de main merci

11negoce-auto.xlsm (245.33 Ko)

Ta base de client est vide. Peut importe ce que tu cherches il n'arrive jamais à faire matcher quoi que ce soit.

Je pense que ton pb vient de là.

(Pour info attention aux accents tu as plein de "é" à la place de "è".

Girodo,

Bonjour Girodo,

même avec une base de donnée remplis il ne prend rien en compte

Bonjour,

Deux remarques :

1- du fait que votre tableau est une table Excel nommée "Tableau1", il est recommandé d'utiliser les propriétés et méthodes associées à cet objet

2- d'autre part, la recherche de la ligne de votre tableau doit au minimum porter sur le nom et le prénom.

A) exemple de code pour récupérer la ligne de "Tableau1" (i_cli) correspondant à un nom et à un prénom

Dim nom As Range, nom1 As Range
Dim i_cli As Integer

Private Sub txtprénom_AfterUpdate()

    With Sheets("Clients").ListObjects("Tableau1")
        With .ListColumns("Nom")
            Set nom = .DataBodyRange.Find(Me.txtnom)
        End With
        If nom Is Nothing Then
            MsgBox " Le nom de ce client n'existe pas.veuillez resaisir un nouveau nom": Exit Sub
        Else
            Do
                Set nom1 = nom
                With .ListColumns("Prénom")
                    i_cli = Application.Match(Me.txtprénom.Value, .DataBodyRange, 0)  'numéro de ligne du tableau (et non de la feuille)
                    If Not IsNumeric(i_cli) Then MsgBox " Le prénom de ce client n'existe pas.veuillez resaisir un nouveau prénom": Exit Sub
                End With

                With .ListColumns("Nom")
                    Set nom = .DataBodyRange.Find(nom)
                End With

            Loop Until nom.Address = nom1.Address
        End If
    End With

End Sub
 

B) par ailleurs exemple de code pour ajouter une ligne dans "Tableau1" en utilisant l'objet associé car avec le code que vous utilisez, je ne suis pas certain que votre tableau soit redimensionné correctement.

Private Sub CommandButton4_Click()
    Dim cell As Range, i As Integer

    If MsgBox("Confirmez-vous L’insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d’ajout ") = vbYes Then
        With Sheets("Clients").ListObjects("Tableau1")
            '// recherche première cellule vide de la colonne N° fact //
            Set cell = .ListColumns("N° fact").Range.Find("", SearchDirection:=xlNext)
            '// si pas de cellule vide, ajout d'une ligne vierge à la fin du tableau et indice de cette ligne
            'sinon indice de la ligne du tableau correspondant à la première cellule vide de la colonne N° fact //
            If cell Is Nothing Then .ListRows.Add: i = .ListRows.Count + 1 _
            Else i = cell.Row - .HeaderRowRange.Row

            '// remplissage de la ligne //
            .ListColumns("N° fact").DataBodyRange.Rows(i) = txtfacture
            .ListColumns("Civilité").DataBodyRange.Rows(i) = ComboBox4
            .ListColumns("Nom").DataBodyRange.Rows(i) = txtnom
            .ListColumns("Prénom").DataBodyRange.Rows(i) = txtprénom
            .ListColumns("Adresse").DataBodyRange.Rows(i) = txtadresse
            .ListColumns("CP").DataBodyRange.Rows(i) = txtcp
            .ListColumns("Ville").DataBodyRange.Rows(i) = txtville
            .ListColumns("Téléphone").DataBodyRange.Rows(i) = txttéléphone
            .ListColumns("Portable").DataBodyRange.Rows(i) = txtportable
            .ListColumns("Marque").DataBodyRange.Rows(i) = txtmarque
            .ListColumns("Modèle").DataBodyRange.Rows(i) = txtmodéle
            .ListColumns("Année").DataBodyRange.Rows(i) = txtannée
            .ListColumns("Couleur").DataBodyRange.Rows(i) = txtcouleur
            .ListColumns("N° de série").DataBodyRange.Rows(i) = txtn°série
            .ListColumns("Kilométre").DataBodyRange.Rows(i) = txtkilométre
            .ListColumns("Immatriculation").DataBodyRange.Rows(i) = txtimmatriculation
            .ListColumns("N° carte grise").DataBodyRange.Rows(i) = txtcartegrise
            .ListColumns("Puissance Fiscale").DataBodyRange.Rows(i) = txtpuissance
            .ListColumns("Energie").DataBodyRange.Rows(i) = ComboBoxénergie
            .ListColumns("Valeur").DataBodyRange.Rows(i) = txtprix
         End With
    End If
End Sub
Rechercher des sujets similaires à "recherchev"