ListBox qui agit sur Texbox et Combox

aeque

XLDnaute Occasionnel
bonjour le fofo

voilà j'aimerai modifier un base de données via list box. Là pas de pb
Par contre je ne modifie que par des textbox et j'aimerai remplacer deux textbox par des combobox. (au lieu de 6 textbox j'aimerai en avoir 4 et 2 combobox)

Et là je n'arrive je ne sais pas comment faire pour compiler les deux. Voici mon code

Merci du coup de main

Code:
Private x As Byte

Private Sub UserForm_INITIALIZE() 
With ListBox1
  .List = Range("emp").Value
  .ColumnCount = 6
  .ColumnWidths = "100;100;100;100;100;100"
End With
End Sub

Private Sub ListBox1_Click() 
For x = 1 To 6 
        Me.Controls("TextBox" & x).Value = Cells(Me.ListBox1.ListIndex + 4, x + 1)
Next x
End Sub

Private Sub CommandButton1_Click() 'bouton "modifier"
For x = 1 To 6
    With Me.ListBox1
        Cells(.ListIndex + 4, x + 1) = Me.Controls("TextBox" & x).Value 
    End With
Next x
Unload Me
End Sub
 

Si...

XLDnaute Barbatruc
Re : ListBox qui agit sur Texbox et Combox

Salut

avex TextBox1... TextBox4 et ComboBox1 ... ComboBox2, essaie
Code:
Private Sub ListBox1_Click()
  For x = 1 To 6
    If x < 5 Then
      Controls("TextBox" & x) = Cells(Me.ListBox1.ListIndex + 4, x + 1)
    Else
      Controls("ComboBox" & x - 4) = Cells(Me.ListBox1.ListIndex + 4, x + 1)
    End If 
  Next
End Sub

Private Sub CommandButton1_Click() 'bouton "modifier"
  With ListBox1
    For x = 1 To 6
      If x < 5 Then
        Cells(.ListIndex + 4, x + 1) = Controls("TextBox" & x)
      Else
       Cells(.ListIndex + 4, x + 1) = Controls("ComboBox" & x - 4)
     End If
    Next
  End With
  Unload Me
End Sub
 
Dernière édition:

Discussions similaires

Réponses
17
Affichages
851
Réponses
4
Affichages
218

Statistiques des forums

Discussions
312 338
Messages
2 087 396
Membres
103 534
dernier inscrit
Kalamymustapha