lock fields in form

T

Ticotion

Hi

I have a form that consists of different input fields ( field1, field2
etc.). What I want to do is to lock the fields until a surtain button
(Button1) has been used. How can this be done?

thank you for your help

Ticotion
 
D

Douglas J. Steele

Lock the controls in the form's Current event:

Private Sub Form_Current()

Me.field1.Locked = True
Me.field2.Locked = True

End Sub

Unlock them in the OnClick event of the button:

Private Sub Button1_Click()

Me.field1.Locked = False
Me.field2.Locked = False

End Sub

It may actually be better to create a form-level sub to toggle the controls:

Private Sub ToggleControls(LockedSetting As Boolean)

Me.field1.Locked = LockedSetting
Me.field2.Locked = LockedSetting

End Sub

and then call that routine from the other routines:

Private Sub Form_Current()

Call ToggleControls(True)

End Sub

Private Sub Button1_Click()

Call ToggleControls(False)

End Sub
 
T

Ticotion

thank you that works

Ticotion

Douglas J. Steele said:
Lock the controls in the form's Current event:

Private Sub Form_Current()

Me.field1.Locked = True
Me.field2.Locked = True

End Sub

Unlock them in the OnClick event of the button:

Private Sub Button1_Click()

Me.field1.Locked = False
Me.field2.Locked = False

End Sub

It may actually be better to create a form-level sub to toggle the controls:

Private Sub ToggleControls(LockedSetting As Boolean)

Me.field1.Locked = LockedSetting
Me.field2.Locked = LockedSetting

End Sub

and then call that routine from the other routines:

Private Sub Form_Current()

Call ToggleControls(True)

End Sub

Private Sub Button1_Click()

Call ToggleControls(False)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top