How to lock a control from code in Form On Current event.

G

GA

Hello,

I have a form which has code in the On Current event that checks the state
of a check box and sets several controls to visible or not visible as the
case may be. It works fine but I also want to set the data Locked property
of the remaining visible controls at the same time as I set some to
invisible.

I can see how you set a form to be either editable or not when it is
opened but I want to control the property of each control whilst the form
is open and I move from record to record.

Thanks - GA
 
R

Rick Brandt

GA said:
Hello,

I have a form which has code in the On Current event that checks the
state of a check box and sets several controls to visible or not
visible as the case may be. It works fine but I also want to set the
data Locked property of the remaining visible controls at the same
time as I set some to invisible.

I can see how you set a form to be either editable or not when it is
opened but I want to control the property of each control whilst the
form is open and I move from record to record.

If you don't mind locking ALL controls (even unbound ones) then you can use...

Me.AllowEdits = False

If you need to lock just "some" of the controls then you will have to set the
Locked property of each of them individually or loop through a collection or set
of common Tag property entries.

Me.ControlName.Locked = True
 
D

Douglas J. Steele

Private Sub Form_Current()

If Me.Control1 = True Then
Me.Control2.Visible = False
Me.Control3.Visible = True
Me.Control3.Enabled = False
Me.Control4.Visible = True
Me.Control4.Enabled = True
Else
Me.Control2.Visible = True
Me.Control3.Visible = True
Me.Control3.Enabled = True
Me.Control4.Visible = False
End If

End Sub
 
G

GA

Excellent. Many thanks to both Rick and Doug. I really do appreciate the
help on those occasions that I get stuck and up to now when all else has
failed the 'volunteers' in here always come up trumps 8^)

I've gone with Me.AllowEdits = False since it does exactly what I wanted.
 

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