Bonjour le forum,
j'ai un message d'erreur "erreur d'éxécution '13' incompatibilité de type lors que je veux ouvrir mon formulaire.
A noter que ce dysfonctionnement apparaît lorsque que ma base de donnée est vidé de toutes données.
QQ 1 peut il m'aider à résoudre ce problème ?
merci et bonne soirée à vous
Option Explicit
Dim Ws As Worksheet
Public nouveau As Boolean
'suppression d'un intervenant'
Private Sub CommandButton4_Click()
If MsgBox("Confirmez-vous la suppression de cet intervenant ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
Rows([a3:a65536].Find(ComboBox1.Value).Row).EntireRow.Delete
Unload Me
UserForm1.Show
Else
'rien
End If
End Sub
'Pour le formulaire
Private Sub UserForm_Initialize()
Dim J As Long
Dim I As Long
Set Ws = Sheets("bdd")
With Me.ComboBox1
For J = 3 To Ws.Range("A" & Rows.Count).End(xlUp).Row
.AddItem Ws.Range("A" & J)
Next J
'incrémente un nouveau numéro à l'ouverture du useform
nouveau = True
I = Feuil1.Cells(Application.Rows.Count, "A").End(xlUp).Row
If nouveau = True Then ComboBox1 = Feuil1.Range("A" & I).Value + 1
End With
End Sub
'Pour la liste déroulante Code client récupère les infos
Private Sub ComboBox1_Change()
Dim Ligne As Long
Dim I As Integer
Dim J As Integer
Dim Tbl
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox1.ListIndex + 3
For I = 1 To 8
Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 1)
Next I
SelectListBox ListBox1, Ws.Cells(Ligne, 10)
SelectListBox ListBox2, Ws.Cells(Ligne, 11)
End Sub
Sub SelectListBox(Lst As MSForms.ListBox, Chaine As String)
Dim Tbl
Dim I As Integer
Dim J As Integer
'dé-sélectionne tout
For I = 0 To Lst.ListCount - 1: Lst.Selected(I) = False: Next I
'splite sur la chaine
Tbl = Split(Chaine, ";")
'boucle sur le tableau et la ListBox afin de sélectionner les choix
For I = 0 To UBound(Tbl) - 1
For J = 0 To Lst.ListCount - 1
If Lst.List(J) = Tbl(I) Then Lst.Selected(J) = True
Next J
Next I
End Sub
'ajouter le Nouvel intervenant à ma bdd
Private Sub CommandButton1_Click()
Dim L As Long
If MsgBox("Confirmez-vous l'insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d'ajout") = vbNo Then Exit Sub
L = Sheets("bdd").Range("A" & Rows.Count).End(xlUp).Row + 1 'Pour placer le nouvel enregistrement ? la premi?re ligne de tableau non vide
Inscrire L
End Sub
'Pour le bouton Modifier
Private Sub CommandButton2_Click()
Dim Ws As Worksheet
Dim L As Long
Dim C As Integer
If MsgBox("Confirmez-vous la modification de ce contact ?", vbYesNo, "Demande de confirmation de modification") = vbNo Then Exit Sub
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
L = Me.ComboBox1.ListIndex + 3
Inscrire L
End Sub
Sub Inscrire(L As Long)
Dim Ws As Worksheet
Dim I As Integer
Dim mobilite As String
Dim domaine As String
Dim Tbl
Range("A" & L).Value = CDbl(ComboBox1)
Range("B" & L).Value = TextBox1
Range("C" & L).Value = TextBox2
Range("D" & L).Value = TextBox3
Range("E" & L).Value = TextBox4
Range("F" & L).Value = TextBox5
Range("G" & L).Value = TextBox6
Range("H" & L).Value = TextBox7
Range("I" & L).Value = TextBox8
Set Ws = Worksheets("bdd")
'récup des choix
For I = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(I) Then domaine = domaine & Me.ListBox1.List(I) & ";"
Next
'splite dans un tableau...
Tbl = Split(domaine, ";")
'et dispatche dans les colonnes
With Ws
.Range("j" & L).Value = domaine
.Range(.Cells(L, 12), .Cells(L, 12 + UBound(Tbl))).Value = Tbl
End With
For I = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(I) Then mobilite = mobilite & Me.ListBox2.List(I) & ";"
Next I
Tbl = Split(mobilite, ";")
With Ws
.Range("K" & L).Value = mobilite
.Range(.Cells(L, 15), .Cells(L, 15 + UBound(Tbl))).Value = Tbl
End With
Unload Me
UserForm1.Show
End Sub
'Pour le bouton Quitter
Private Sub CommandButton3_Click()
Unload Me
End Sub
'vérifier le choix de ma listbox mobilité
Private Sub CommandButton6_Click()
Dim Msg As String
Dim I As Integer
For I = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(I) Then
Msg = Msg & Me.ListBox2.List(I) & vbNewLine
End If
Next I
MsgBox Msg
End Sub
'vérifier le choix de ma listbox domaine
Private Sub CommandButton5_Click()
Dim Msg As String
Dim I As Integer
For I = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(I) Then
Msg = Msg & Me.ListBox1.List(I) & vbNewLine
End If
Next I
MsgBox Msg
End Sub
'limite le choix multiselect de la listbox1
Private Sub ListBox1_change()
Static nb As Integer
Dim choisi As Integer, max As Integer
max = 3
choisi = ListBox1.ListIndex
If ListBox1.Selected(choisi) = False Then nb = nb - 1: Exit Sub
If nb >= max Then ListBox1.Selected(choisi) = False
nb = nb + 1
End Sub
'limite le choix multiselect de la listbox1
Private Sub ListBox2_change()
Static nb As Integer
Dim choisi As Integer, max As Integer
max = 20
choisi = ListBox2.ListIndex
If ListBox2.Selected(choisi) = False Then nb = nb - 1: Exit Sub
If nb >= max Then ListBox2.Selected(choisi) = False
nb = nb + 1
End Sub