XL 2016 Code pour faire défiler les photos

  • Initiateur de la discussion Initiateur de la discussion Djibysadji
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Djibysadji

XLDnaute Nouveau
Salut la communauté!
Je sollicite encore votre soutien.
Mon projet est de concevoir un formulaire où je pourrais insérer du texte et des photos à partir d'une base de données et les faire défiler à l'aide d'une comboBox alimentée ou avec les boutons suivant et précédent.
J'ai presque réussi car je parviens à faire défiler les données texte. Le seul hic est qu'il n'y a que la photo par défaut qui vient à la place des personnes dont les info s'affichent dans les textBox.
Pour y voir clair et vous permettre de m'aider plus facilement, je joins ci-dessous une base de données fictives, mais mon Userform et le code effectué.

A B C D E F G H I
1PrénomNomDate naissanceLieu naissanceSituat de familNb d'enfantsAdresse CivileCNI Photo
2Jennie Olimba12/07/1900JupiterMariée0Jupiter12345567oui
3FrankHouston13/08/1901VénusMarié2Vénus7654321oui
4JeanPierre14/09/1902MarsCélibataire1Mars9876453oui
SolangeLegentil15/10/1903TerreDivorcée4Terre2345667oui

1031664


Option Explicit
Dim i As Integer, lr As Integer
Dim CurrentRow As Long

Private Sub cmdModifier_Click()
i = Me.ComboBox1.ListIndex + 2
If Me.ComboBox1.Value = "" Then
MsgBox "veuillez sélectionner une donnée dans la liste déroulante"
Else
Cells(i, 1).Value = Me.TextBox1.Value
Cells(i, 2).Value = Me.TextBox2.Value
Cells(i, 3).Value = Me.TextBox3.Value
Cells(i, 4).Value = Me.TextBox4.Value
Cells(i, 5).Value = Me.TextBox5.Value
Cells(i, 6).Value = Me.TextBox6.Value
Cells(i, 7).Value = Me.TextBox7.Value
Cells(i, 8).Value = Me.TextBox8.Value
Cells(i, 9).Value = Me.TextBox9.Value
e
End If
If Me.CheckBox1 = True Then
Cells(i, 10).Value = "oui"
Else
Cells(i, 10).Value = "oui"
End If


End Sub

Private Sub CmdPrécédent_Click()
CurrentRow = CurrentRow - 1
If CurrentRow > 1 Then

TextBox1.Text = Cells(CurrentRow, 1).Value
TextBox2.Text = Cells(CurrentRow, 2).Value
TextBox3.Text = Cells(CurrentRow, 3).Value
TextBox4.Text = Cells(CurrentRow, 4).Value
TextBox5.Text = Cells(CurrentRow, 5).Value
TextBox6.Text = Cells(CurrentRow, 6).Value
TextBox7.Text = Cells(CurrentRow, 7).Value
TextBox8.Text = Cells(CurrentRow, 8).Value
TextBox9.Text = Cells(CurrentRow, 9).Value

ElseIf CurrentRow = 1 Then
CurrentRow = CurrentRow + 1
MsgBox "Vous êtes au premier enregistrement"
End If

End Sub

Private Sub CmdQuitter_Click()
Unload Me
End Sub

Private Sub cmdSuivant_Click()
lr = Sheets(1).Range("A100").End(xlUp).Row
CurrentRow = CurrentRow + 1

If CurrentRow = lr + 1 Then
CurrentRow = lr
MsgBox "Vous êtes au dernier enregistrement"

End If
TextBox1.Text = Cells(CurrentRow, 1).Value
TextBox2.Text = Cells(CurrentRow, 2).Value
TextBox3.Text = Cells(CurrentRow, 3).Value
TextBox4.Text = Cells(CurrentRow, 4).Value
TextBox5.Text = Cells(CurrentRow, 5).Value
TextBox6.Text = Cells(CurrentRow, 6).Value
TextBox7.Text = Cells(CurrentRow, 7).Value
TextBox8.Text = Cells(CurrentRow, 8).Value
TextBox9.Text = Cells(CurrentRow, 9).Value

End Sub

Private Sub CmdValider_Click()
If MsgBox("Validez-vous ces données?", vbYesNo, "Validation") = vbYes Then
lr = Sheets(1).Range("A100").End(xlUp).Row + 1
Cells(lr, 1).Value = Me.TextBox1
Cells(lr, 2).Value = Me.TextBox2
Cells(lr, 3).Value = Me.TextBox3
Cells(lr, 4).Value = Me.TextBox4
Cells(lr, 5).Value = Me.TextBox5
Cells(lr, 6).Value = Me.TextBox6
Cells(lr, 7).Value = Me.TextBox7
Cells(lr, 8).Value = Me.TextBox8
Cells(lr, 9).Value = Me.TextBox9

If Me.CheckBox1 = True Then
Cells(lr, 10).Value = "oui"
Else
Cells(lr, 10).Value = "non"
End If

End If
Range("a2").Select
Me.TextBox1 = ""
Me.TextBox2 = ""
Me.TextBox3 = ""
Me.TextBox4 = ""
Me.TextBox5 = ""
Me.TextBox6 = ""
Me.TextBox7 = ""
Me.TextBox8 = ""
Me.TextBox9 = ""

End Sub

Private Sub ComboBox1_Change()
Dim Photo As String

i = Me.ComboBox1.ListIndex + 2
Me.TextBox1.Text = Cells(i, 1).Value
Me.TextBox2.Text = Cells(i, 2).Value
Me.TextBox3.Text = Cells(i, 3).Value
Me.TextBox4.Text = Cells(i, 4).Value
Me.TextBox5.Text = Cells(i, 5).Value
Me.TextBox6.Text = Cells(i, 6).Value
Me.TextBox7.Text = Cells(i, 7).Value
Me.TextBox8.Text = Cells(i, 8).Value
Me.TextBox9.Text = Cells(i, 9).Value

On Error GoTo defaut
Photo = ComboBox1.Value
Image1.Picture = LoadPicture("C:\Users\HP\OneDrive\Bureau\Photopersonnels" & Photo & ".jpg")
Exit Sub

defaut:
Image1.Picture = LoadPicture("C:\Users\HP\OneDrive\Bureau\Photopersonnels\Default.jpg")

End Sub

Private Sub TextBox1_Change()
On Error GoTo defaut
Dim Photo As String

Photo = TextBox1.Value
Image1.Picture = LoadPicture("C:\Users\HP\OneDrive\Bureau\Photopersonnels\" & Photo & ".jpg")
Exit Sub

defaut:
Image1.Picture = LoadPicture("C:\Users\HP\OneDrive\Bureau\Photopersonnels\Default.jpg")

End Sub

Private Sub UserForm_Initialize()

CurrentRow = 1
lr = Sheets(1).Range("A100").End(xlUp).Row
For i = 2 To lr
ComboBox1.AddItem Sheets("SOURCE").Cells(i, 1)
Next i

End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
250
Réponses
3
Affichages
599
Réponses
2
Affichages
405
  • Question Question
Microsoft 365 VBA insert photos
Réponses
12
Affichages
795
Réponses
3
Affichages
240
Réponses
3
Affichages
459
Réponses
35
Affichages
2 K
Retour