Formulaire VBA erreur

Bonjour,

j'ai réalisé pour la première fois un formulaire avec 2 combobox, 17 textbox et 3 commandbutton

je ne comprends pas cela ne fonctionne pas j'ai un message d'erreur d’exécution - objet spécifié introuvable !

pouvez vous m'aider svp ?

Merci d'avance

voici mon userform

'Pour le formulaire

Private Sub UserForm_Initialize()

Dim J As Long

Dim I As Integer

ComboBox2.ColumnCount = 1 'Pour la liste déroulante Civilité

ComboBox2.List() = Array("", "M.", "Mme", "Mlle")

Set Ws = Sheets("Clients") 'Correspond au nom de votre onglet dans le fichier Excel

With ComboBox1

For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row

.AddItem Ws.Range("A" & J)

Next J

End With

For I = 1 To 17

Me.Controls("TextBox" & S).Visible = True

Next I

End Sub

'Pour la liste déroulante Code client

Private Sub ComboBox1_Change()

Dim Ligne As Long

Dim I As Integer

If Me.ComboBox1.ListIndex = -1 Then Exit Sub

Ligne = Me.ComboBox1.ListIndex + 2

ComboBox2 = Ws.Cells(Ligne, "B")

For I = 1 To 17

Me.Controls("TextBox" & S) = Ws.Cells(Ligne, I + 2)

Next I

End Sub

'Pour le bouton Nouveau contact

Private Sub CommandButton1_Click()

Dim L As Integer

If MsgBox("Confirmez-vous l’insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d’ajout") = vbYes Then

L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide

Range("A" & L).Value = ComboBox1

Range("B" & L).Value = ComboBox2

Range("C" & L).Value = TextBox1

Range("D" & L).Value = TextBox2

Range("E" & L).Value = TextBox3

Range("F" & L).Value = TextBox4

Range("G" & L).Value = TextBox5

Range("H" & L).Value = TextBox6

Range("I" & L).Value = TextBox7

Range("J" & L).Value = TextBox8

Range("K" & L).Value = TextBox9

Range("L" & L).Value = TextBox10

Range("M" & L).Value = TextBox11

Range("N" & L).Value = TextBox12

Range("O" & L).Value = TextBox13

Range("P" & L).Value = TextBox14

Range("Q" & L).Value = TextBox15

Range("R" & L).Value = TextBox16

Range("S" & L).Value = TextBox17

End If

End Sub

'Pour le bouton Modifier

Private Sub CommandButton2_Click()

Dim Ligne As Long

Dim I As Integer

If MsgBox("Confirmez-vous la modification de ce contact ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then

If Me.ComboBox1.ListIndex = -1 Then Exit Sub

Ligne = Me.ComboBox1.ListIndex + 2

Ws.Cells(Ligne, "B") = ComboBox2

For I = 1 To 17

If Me.Controls("TextBox" & S).Visible = True Then

Ws.Cells(Ligne, I + 2) = Me.Controls("TextBox" & S)

End If

Next I

End If

End Sub

'Pour le bouton Quitter

Private Sub CommandButton3_Click()

Unload Me

End Sub

End Sub

Bonjour,

Je ne sais pas si c'est ton code ou tu sais déboguer le code. Il y a des erreurs. Principalement,

Dans les boucles FOR :

l'indice est de : I , or tu utilise S à l'intérieur de boucle.

Les TextBox1 et TextBox2 n'existent pas alors que dans les boucles ils sont appelés. C'est le bug qui engendre le message d'erreur. Il va falloir assainir le code et venir nous questionner si le problème persiste.

super !! merci beaucoup

le formulaire fonctionne mais encore des bugs, car les boutons nouvea contact, modifier et quitter ne marche pas !

pouvez vous me dire ce qui ne va pas ?

merci

nicolas

voici le userform avec modif.

'Pour le formulaire

Private Sub UserForm_Initialize()

Dim J As Long

Dim I As Integer

ComboBox2.ColumnCount = 1 'Pour la liste déroulante Civilité

ComboBox2.List() = Array("", "M.", "Mme", "Mlle")

Set Ws = Sheets("Clients") 'Correspond au nom de votre onglet dans le fichier Excel

With ComboBox1

For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row

.AddItem Ws.Range("A" & J)

Next J

End With

For S = 1 To 17

Me.Controls("TextBox" & S).Visible = True

Next S

End Sub

'Pour la liste déroulante Code client

Private Sub ComboBox1_Change()

Dim Ligne As Long

Dim I As Integer

If Me.ComboBox1.ListIndex = -1 Then Exit Sub

Ligne = Me.ComboBox1.ListIndex + 2

ComboBox2 = Ws.Cells(Ligne, "B")

For S = 1 To 17

Me.Controls("TextBox" & S) = Ws.Cells(Ligne, I + 2)

Next S

End Sub

'Pour le bouton Nouveau contact

Private Sub CommandButton1_Click()

Dim L As Integer

If MsgBox("Confirmez-vous l’insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d’ajout") = vbYes Then

L = Sheets("Clients").Range("A65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide

Range("A" & L).Value = ComboBox1

Range("B" & L).Value = ComboBox2

Range("C" & L).Value = TextBox1

Range("D" & L).Value = TextBox2

Range("E" & L).Value = TextBox3

Range("F" & L).Value = TextBox4

Range("G" & L).Value = TextBox5

Range("H" & L).Value = TextBox6

Range("I" & L).Value = TextBox7

Range("J" & L).Value = TextBox8

Range("K" & L).Value = TextBox9

Range("L" & L).Value = TextBox10

Range("M" & L).Value = TextBox11

Range("N" & L).Value = TextBox12

Range("O" & L).Value = TextBox13

Range("P" & L).Value = TextBox14

Range("Q" & L).Value = TextBox15

Range("R" & L).Value = TextBox16

Range("S" & L).Value = TextBox17

End If

End Sub

'Pour le bouton Modifier

Private Sub CommandButton2_Click()

Dim Ligne As Long

Dim I As Integer

Dim Ws As Worksheet

If MsgBox("Confirmez-vous la modification de ce contact ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then

If Me.ComboBox1.ListIndex = -1 Then Exit Sub

Ligne = Me.ComboBox1.ListIndex + 2

Ws.Cells(Ligne, "B") = ComboBox2

For S = 1 To 17

If Me.Controls("TextBox" & I).Visible = True Then

Ws.Cells(Ligne, I + 2) = Me.Controls("TextBox" & I)

End If

Next S

End If

End Sub

'Pour le bouton Quitter

Private Sub CommandButton3_Click()

Unload Me

End Sub

Rechercher des sujets similaires à "formulaire vba erreur"