Code VBA

Fermé
Debutant.VBA Messages postés 9 Date d'inscription vendredi 7 avril 2017 Statut Membre Dernière intervention 30 avril 2017 - 7 avril 2017 à 18:38
Salut

j'ai réalisé une userform sur la quelle se trouve combobox1 et listbox1

mon objectif est qu'en sélectionnant une lettre alphabétique dans la combobox1, toutes personnes enregistrés sous cette lettre s’affiche automatiquement dans la listbox1

puis en cliquant sur chaque nom de la listbox1 le reste des informations de cette personne affiche dans les autre champs y compris la photo

le tableau commence de la colonne A à Y soit 25 colonnes la photo est enregistrer automatiquement dans un dossier nommé PHOTOS.

les la colonne B est est la colonne de la lettre alphabétique et les noms dans la colonne C

la feuille est nommé IDENTIFICATION

Mon souci est que la photo n'affiche pas pendant que le reste marche correctement

voici le code que j’ai puis utilisé:

ou voir la pièce jointe .


Private Sub ListBox1_Click()
Dim I As Integer, lig As Long

'raz des TextBox et OptionButton
For C = 1 To 21
Me.Controls("Textbox" & C) = ""
Next C

For C = 1 To 4
With Me.Controls("OptionButton" & C)
.Value = False
.ForeColor = vbBlack
End With
Next C
'recuperation ligne Infos
lig = ListBox1.List(ListBox1.ListIndex, 1) 'ligne choix
'remplissage Textbox
'A D E F G H IO J K L M N O P QO R S T U V W X Y
'1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
With Worksheets("IDENTIFICATION")
Ntxt = 1
For C = 1 To 25
If C = 21 Then
x = x
End If
If C <> 2 And C <> 3 And C <> 9 And C <> 17 Then
Me.Controls("TextBox" & Ntxt) = .Cells(lig, C)
Ntxt = Ntxt + 1
ElseIf C = 9 Then 'Marié/Célibataire
If .Cells(lig, 9) = "Marié" Then
With OptionButton1
.Value = True
.ForeColor = vbRed
End With
With OptionButton2
.ForeColor = vbBlack
End With
Else
With OptionButton2
.Value = True
.ForeColor = vbRed
End With
With OptionButton1
.ForeColor = vbBlack
End With
End If
ElseIf C = 17 Then 'Batisé(e): Oui/Non
If .Cells(lig, 17) = "Oui" Then
With OptionButton3
.Value = True
.ForeColor = vbRed
End With
With OptionButton4
.ForeColor = vbBlack
End With
Else
With OptionButton4
.Value = True
.ForeColor = vbRed
End With
With OptionButton3
.ForeColor = vbBlack
If Dir(ThisWorkbook.Path & "\" & "PHOTOS\" & ComboBox1 & ".jpg") = "" Then
Me.Image1.Picture = LoadPicture("")
Else
Me.Image1.Picture = LoadPicture(ThisWorkbook.Path & "\" & "PHOTOS\" & ComboBox1 & ".jpg")

End If
End With
End If
End If
Next C
End With

End Sub


voir pièce jointe


https://www.cjoint.com/c/GDhqJ2QbkJ2