Com bloquejar i desbloquejar tots els controls d'un formulari d'Access mitjantçant codi VBA
Per bloquejar tots els controls d'un formulari al passar d'un registre a un altre, col·loquem el següent codi en l'event "al activar registro"
Dim ctrl As Control
For Each ctrl In Me.Controls
With ctrl
Select Case .ControlType
Case acTextBox
.Locked = True
Case acComboBox
.Locked = True
Case acLabel
.SpecialEffect = acEffectShadow
End Select
End With
Next ctrl
For Each ctrl In Me.Controls
With ctrl
Select Case .ControlType
Case acTextBox
.Locked = True
Case acComboBox
.Locked = True
Case acLabel
.SpecialEffect = acEffectShadow
End Select
End With
Next ctrl
Aquest codi impedeix fer qualsevol modificació no desitjada d'algun dels camps del registre actiu.
També podem desbloquejar els camps mitjantçant el següent codi situat en un botó que podria tenir per nom Modificar i introduir el següent codi en l'event "al hacer clic"
Dim ctrl As Control
For Each ctrl In Me.Controls
With ctrl
Select Case .ControlType
Case acTextBox
.Locked = False
Case acComboBox
.Locked = False
Case acLabel
.SpecialEffect = acEffectNormal
End Select
End With
Next ctrl
For Each ctrl In Me.Controls
With ctrl
Select Case .ControlType
Case acTextBox
.Locked = False
Case acComboBox
.Locked = False
Case acLabel
.SpecialEffect = acEffectNormal
End Select
End With
Next ctrl
Comentaris
Publica un comentari a l'entrada