MS ACCESS: LOCK FIELD ON_EXIT

G

Guest

How can I lock a field on exit? I do not want to lock the whole form. The
form has almost 20 fields. Once the user fills all the fields or most of the
fields and closes the form, I want one specific field (year) to be locked so
that when the user reopens the forms he cannot change that specific field but
should be able to edit any of the other fields. The field name is year
 
R

Rick Brandt

Paul Joseph said:
How can I lock a field on exit? I do not want to lock the whole form. The
form has almost 20 fields. Once the user fills all the fields or most of the
fields and closes the form, I want one specific field (year) to be locked so
that when the user reopens the forms he cannot change that specific field but
should be able to edit any of the other fields. The field name is year

In the Current event of the form...

Me![Year].Locked = Not IsNull(Me![Year])

This assumes that the control bound to the field [Year] is also named "Year".

Bad name for a field by the way. There is a function named Year and thus it is
a reserved word in Access and you could see problems where you are referring to
the field and Access thinks you want the function.
 
S

Steve Schapel

Paul,

Put code like this on the Current event of the form...
Me![Year].Locked = Not IsNull(Me![Year])

By the way, as an aside, the word Year is a Reserved Word (i.e. has a
special meaning) in Access, and it is best not to use it as the name of
a field or control or database object.
 
R

Rick Brandt

Hey, great minds think alike :)

Steve Schapel said:
Paul,

Put code like this on the Current event of the form...
Me![Year].Locked = Not IsNull(Me![Year])

By the way, as an aside, the word Year is a Reserved Word (i.e. has a special
meaning) in Access, and it is best not to use it as the name of a field or
control or database object.

--
Steve Schapel, Microsoft Access MVP


Paul said:
How can I lock a field on exit? I do not want to lock the whole form. The
form has almost 20 fields. Once the user fills all the fields or most of the
fields and closes the form, I want one specific field (year) to be locked so
that when the user reopens the forms he cannot change that specific field but
should be able to edit any of the other fields. The field name is year
 
S

Steve Schapel

Yeah, if I'd known you were around I could have gone for a coffee
instead :)
 

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

Similar Threads

Lock Fields on Form 1
on_exit 2
Instant Totals on Continuous Forms 2
Locked fields 1
conditional field lock 5
Add record then lock field 5
Null Field to Interupt Closing 4
Lock next record 3

Top