Lock text fields in Access Database Forms

J

Joseph Stevens

I'm trying to lock three text fields: SS#, Name, and ID to prevent them from
being typed into. I want to create a command button that you click to unlock
the fields for editing. When clicked the name on the button should change to
"unlocked".

Thanks!
 
S

smk23

Joe,
It sounds like you are trying to enable and disable some controls on your
form. You could use a togglel button so you can turn the enable function off
and on. The vba code on your button (whether command button or toggel button)
would be:

To allow user to enter data:

Me.NameOfControl.Enabled = True

To prevent data entry:

Me.NameOfControl.Enabled = False
 
K

Klatuu

Here is some "air" (untested) code that will do what you want. It should go
in the Click event of your button.

Dim blnLocked as Boolena

blnLocked = Me.cmdLock.Caption = "Locked"
Me.txtSSN.Locked = blnLocked
Me.txtName.Locked = blnLocked
Me.txtID.Locked = blnLocked
Me.cmdLock.Caption = IIf(blnLocked, "Unlocked", "Locked")

That's all there is to it.
 
Top