XL 2016 Textbox protéger lors de la consultation

ngexcel

XLDnaute Occasionnel
Bonjour
j ai pris comme exemple un model existant
ma question j ai des textbox je voudrais le locked quand je les consultes et les déprotéger quand je suis en saisie
dans l'exemple quand je clic sur fiche vierge je peux saisir mais quand je consulte par la listbox je veux que toutes les textbox soient protégés contre un mauvaise manip
merci de votre aide
 

Pièces jointes

  • saisie.xlsm
    26.6 KB · Affichages: 20

Staple1600

XLDnaute Barbatruc
Bonsoir

=>ngexcel
Remplace ces deux procédures dans ton fichier exemple par celles-ci
VB:
Private Sub UserForm_Initialize()
Dim c As Control
   Set f = Sheets("bd")
   lignefin = f.[a65000].End(xlUp).Row
   If lignefin > 2 Then
     Clé = f.Range("A2:A" & f.[a65000].End(xlUp).Row)
     Tri Clé, LBound(Clé), UBound(Clé)
     Me.CléCherchée.List = Clé
     Me.CléCherchée.ListIndex = -1
   Else
     If lignefin = 2 Then Me.CléCherchée.AddItem f.Range("A2")
   End If
   Me.Service.List = Array("Etudes", "Informatique", "Marketing", "Production")
   Me.Loisirs.List = Array("Lecture", "Cinéma", "Vélo", "Natation", "Internet")
   For Each c In Me.Controls
        If TypeName(c) = "TextBox" Then
            c.Locked = True
        End If
    Next
End Sub
et
VB:
Private Sub B_ajout_Click()
Dim c As Control
For Each c In Me.Controls
      If TypeName(c) = "TextBox" Then
          c.Locked = False
      End If
Next
CléCherchée.ListIndex = -1
ligneEnreg = f.[a65000].End(xlUp).Row + 1
Me.enreg = ligneEnreg
Me.nom = ""
Me.Marié = False
Me.Date_naissance = ""
Me.Service = ""
Me.Ville = ""
Me.Salaire = ""
For j = 0 To Me.Loisirs.ListCount - 1: Me.Loisirs.Selected(j) = False: Next j
Me.nom.SetFocus
End Sub
Je te laisse chercher les différences.
 

Discussions similaires

Statistiques des forums

Discussions
312 307
Messages
2 087 101
Membres
103 468
dernier inscrit
TRINITY