Petit bug sur tableau mais je trouve pas pourquoi

Résolu/Fermé
missharck Messages postés 29 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 15 juin 2015 - Modifié par missharck le 5/07/2014 à 23:17
missharck Messages postés 29 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 15 juin 2015 - 7 juil. 2014 à 13:38
Bonjour,
je suis entrain de faire un tableau en vba et je rencontre une difficultés au moment de l'utiliser en voici la raison :

une base de donnée avec nom /prénom /num de badge/tel entre ces colonnes d'autres données (adresse postal , courriel,...)

voici mon code :
Option Explicit
Option Compare Text
Private x As Variant
Private pl As Range
Private cel As Range
Private nl As Long
Private Sub TextBox1_Change()

End Sub

Private Sub TextBox2_Change()

End Sub

Private Sub TextBox3_Change()

End Sub

Private Sub TextBox4_Change()

End Sub

Private Sub TextBox6_Change()

End Sub

Private Sub TextBox7_Change()

End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub Label3_Click()

End Sub

Private Sub Label4_Click()

End Sub

Private Sub Label5_Click()

End Sub

Private Sub Label6_Click()

End Sub

Private Sub Label7_Click()

End Sub


Private Sub CommandButton1_Click()
' Valider
Dim dest As Range
With Sheets("BD")
If nl = 0 Then

Set dest = .Cells(Application.Rows.Count, 1).End(xlUp).Offset(1, 0)
Else
Set dest = .Cells(nl, 1)
End If
End With
For x = 1 To 6
dest.Value = Me.Controls("TextBox1").Value
dest.Offset(0, x).Value = Me.Controls("TextBox" & x + 1).Value
Next x
Unload Me
userform1.Show
End Sub

Private Sub ComboBox1_Change()

Me.ListBox1.Clear
For Each cel In pl
If CStr(cel.Value) = CStr(Me.ComboBox1.Value) Then
nl = cel.Row
With Me.ListBox1
.AddItem Sheets("BD").Cells(cel.Row, 1)
.List(.ListCount - 1, 1) = Sheets("BD").Cells(nl, 2)
.List(.ListCount - 1, 2) = nl
End With
End If
Next cel
If Me.ListBox1.ListCount = 1 Then Me.ListBox1.ListIndex = 0
End Sub

Private Sub ListBox1_Click()

nl = Me.ListBox1.Column(2, Me.ListBox1.ListIndex)
For x = 0 To 7
Me.Controls("TextBox" & x + 1).Value = Sheets("BD").Cells(nl, 1 + x)
Next x

With Me.TextBox1
' .SetFocus
.SelStart = 0
.SelLength = Len(.Value)
End With
End Sub

Private Sub OptionButton2_Click()
ComboBox1.Visible = True
Call obG1
End Sub

Private Sub OptionButton3_Click()
ComboBox1.Visible = True
Call obG2
End Sub

Private Sub OptionButton4_Click()
ComboBox1.Visible = True
Call obG2
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub OptionButton1_Click()
ComboBox1.Visible = True
Call obG1
End Sub

Private Sub obG1()
Dim col As Variant
Dim dico As Object
Dim tbl As Variant
Dim I As Variant
Dim j As Variant
Dim temp As Variant

userform1.ComboBox1.Clear
col = IIf(userform1.OptionButton2.Value = True, 7, 1)
With Sheets("BD")
Set pl = .Range(.Cells(2, col), .Cells(Application.Rows.Count, col).End(xlUp))
End With

Set dico = CreateObject("scripting.dictionary")
For Each cel In pl
dico(cel.Value) = ""
Next cel
tbl = dico.keys


For I = 0 To UBound(tbl, 1)
For j = 0 To UBound(tbl, 1)
If tbl(I) < tbl(j) Then
temp = tbl(I)
tbl(I) = tbl(j)
tbl(j) = temp
End If
Next j
Next I
userform1.ComboBox1.List = tbl
End Sub

Private Sub obG2()
Dim col As Variant
Dim dico As Object
Dim tbl As Variant
Dim I As Variant
Dim j As Variant
Dim temp As Variant

userform1.ComboBox1.Clear
col = IIf(userform1.OptionButton4.Value = True, 5, 4)
With Sheets("BD")
Set pl = .Range(.Cells(2, col), .Cells(Application.Rows.Count, col).End(xlUp))
End With

Set dico = CreateObject("scripting.dictionary")
For Each cel In pl
dico(cel.Value) = ""
Next cel
tbl = dico.keys


For I = 0 To UBound(tbl, 1)
For j = 0 To UBound(tbl, 1)
If tbl(I) < tbl(j) Then
temp = tbl(I)
tbl(I) = tbl(j)
tbl(j) = temp
End If
Next j
Next I
userform1.ComboBox1.List = tbl
End Sub

mon problème est le suivant quant il me renvoie les données sur ma list box, si je clic sur un nom il me met une erreur d'exécution '-2147024809(80070057) objet spécifié introuvable. quant je clic sur débogage il me met sur la partie de code suivante :

 Me.Controls("TextBox" & x + 1).Value = Sheets("BD").Cells(nl, 1 + x)

c'est pourtant correcte .... à l'aide ! ! !

A voir également:

10 réponses

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 702
6 juil. 2014 à 08:49
Bonjour,

Private Sub ListBox1_Click()

nl = Me.ListBox1.Column(2, Me.ListBox1.ListIndex)
For x = 0 To 7
Me.Controls("TextBox" & x + 1).Value = Sheets("BD").Cells(nl, 1 + x)
Next x

With Me.TextBox1
' .SetFocus
.SelStart = 0
.SelLength = Len(.Value)
End With
End Sub

vous avez 7 textbox de 1 a 7 , y a pas de 8. Il faut revoir votre comptage
0
missharck Messages postés 29 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 15 juin 2015 7
Modifié par missharck le 6/07/2014 à 09:23
bonjour,
oui j'ai 7 textbox
j'ai corrigé la ligne
For x = 0 To 7
en la remplacant par
For x = 0 To 6
mais le problème reste inchangé
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 702
6 juil. 2014 à 11:19
Re,

Desole, mais chez moi, ca marche, y a autre chose.

x est egal a quoi au moment de l'erreur ????
0
missharck Messages postés 29 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 15 juin 2015 7
6 juil. 2014 à 14:32
je la voie ou la valeur de x au moment du plantage?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 702
Modifié par f894009 le 6/07/2014 à 15:46
Re,

quand vous avez l'erreur, click sur debugage et passez le curseur souris sur x de la ligne en erreur
0
missharck Messages postés 29 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 15 juin 2015 7
6 juil. 2014 à 19:19
il me marque 99
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 702
7 juil. 2014 à 06:50
Re,

Y a comme un probleme !!!!

pouvez-vous mettre votre fichier a dispo sur : https://www.cjoint.com/ en modifiant les donnees qui pourraient etre confidentielles
0
missharck Messages postés 29 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 15 juin 2015 7
7 juil. 2014 à 08:51
bonjour
je ne peux pas j'ai un listing de 200 personnes
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 702
7 juil. 2014 à 10:35
Re,

votre fichier avec seulement le code VBA complet, c'est possible ?????
0
missharck Messages postés 29 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 15 juin 2015 7
7 juil. 2014 à 13:38
je suis arrivée a résoudre le problème.
sur ma feuil1 les lignes que j'avais mise pour mettre la commande sur mon bouton étaient fausses.

Sub Affiche()
UserForm1.Shown
End Sub

remplacé par

Sub Affiche()
UserForm1.Show
End Sub
0