On Open, Set a field to locked.

  • Thread starter Thread starter Kathy Webster
  • Start date Start date
K

Kathy Webster

How do you set a field to "locked" on the OnOpen event of a form?
I don't always want it to be locked, just sometimes. So I don't want to
permanently set the control's property to "locked" in its design.
 
You have to use the OnLoad event because the Open event is too early to
reference a control on your form. Me.ControlName.Locked = True should do it.
 
How do you set a field to "locked" on the OnOpen event of a form?
I don't always want it to be locked, just sometimes. So I don't want to
permanently set the control's property to "locked" in its design.

You can't set a *field* to locked, but you can set a *control* (bound to a
field):

Me!controlname.Locked = True

Open the form in design view; view its properties; click the ... icon by the
Open event, and choose Code Builder. Access will give you a Sub and End Sub
line, edit this in between.

You'll need to unlock the control in some other appropriate form event.

John W. Vinson [MVP]
 
ou have to use the OnLoad event because the Open event is too early to
reference a control on your form.

oops! Quite right; thanks ruralguy!

John W. Vinson [MVP]
 
NP John, I can't count how namy times you've helped me so you are very
welcome.
 
NP John, I can't count how namy times you've helped me so you are very
welcome.

Nothing makes a good teacher happier than being corrected by a student!

John W. Vinson [MVP]
 
"...I don't want to permanently set the control's property to "locked" in its
design."

How I finally lost it, guys? What's the difference in setting a control's
Locked property in Design View (which the OP says she doesn't want to do) and
doing it in FormLoad? Shouldn't someone just tell Kathy that neither way
"permanently" sets it to Locked? That either way she'll have to unlock and
then lock it back again in code?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
"...I don't want to permanently set the control's property to "locked" in its
design."

How I finally lost it, guys? What's the difference in setting a control's
Locked property in Design View (which the OP says she doesn't want to do) and
doing it in FormLoad? Shouldn't someone just tell Kathy that neither way
"permanently" sets it to Locked? That either way she'll have to unlock and
then lock it back again in code?

Good point, Linq. Yes, setting the property in the Open (or Load) event indeed
has the same effect for the user as just setting it in design view!

John W. Vinson [MVP]
 
Its because sometimes I want the form to open so that the user can create a
NEW record. Later, that same form will open and I want the users to be able
to edit everything EXCEPT the name field. Only a supervisor should be able
to change a name once the record is created. This is because a lot of users
think they should type a new name in the name field to FIND a different
record. I don't know where they get this from, but a lot of users think
this.
 
Its because sometimes I want the form to open so that the user can create a
NEW record. Later, that same form will open and I want the users to be able
to edit everything EXCEPT the name field. Only a supervisor should be able
to change a name once the record is created. This is because a lot of users
think they should type a new name in the name field to FIND a different
record. I don't know where they get this from, but a lot of users think
this.

I'd either use two forms, one for users and one for supervisors; or have the
form set with the field locked, and have a command button on the form to open
it for editing. This button could check the CurrentUser() function to see if
this user is allowed to edit the data.

You can also toggle the Enabled property of the textbox in the form's
Beforeinsert and AfterInsert events.

John W. Vinson [MVP]
 
Back
Top