locking a field

G

Guest

Is there a way I can lock a field after data has been entered? For example,
I have a field called Scheduled_Staff. After a person has been selected from
this menu, I would like to field to be read-only.

Thanks!
 
R

Rick B

Please note, this is asked and answered all the time. In the future, I'd
suggest you search for your answers before posting a new thread. The
easiest way I have found is to go to www.google.com, click the "groups"
option, and enter a search string similar to the following...



microsoft.public.access lock field
 
G

Guest

Thanks for your reply Rick - but I did do a search for this prior to my post
and did not find an answer to my question.
 
R

Rick B

I think this post answers your question.

----------------------------------------------

in the form's OnCurrent event, add a procedure (as i described in my
previous post) and add the following code:

Me!MyControlName.Locked = Not IsNull(Me!MyControlName)
(notice that you have to use a specific control name in this line of code)


the Current event fires when you first open the form, because the focus
settles on a single record, and fires again each time you move from one
record to another. so you can lock/unlock any number of controls for the
appropriate conditions of each record.
if you want to lock control(s) in the current record after data entry is
completed, *without* moving to another record, then add the same code to the
form's AfterUpdate event *in addition to* the OnCurrent event.
 
R

Rick B

Here is a similar post...

Use the Current event of the form:

Private Sub Form_Current()
Me.MytextBox.Locked = Len(Me.MytextBox & "") > 0
End Sub


Note that the above statement is merely a short form for:


if len(me.myTextbox & "") > 0 then
me.mytextbox.locked=true
else
me.mytextbox.locked=false
endif


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
 
G

Guest

Thanks for your help Rick! It worked!

Rick B said:
I think this post answers your question.

----------------------------------------------

in the form's OnCurrent event, add a procedure (as i described in my
previous post) and add the following code:

Me!MyControlName.Locked = Not IsNull(Me!MyControlName)
(notice that you have to use a specific control name in this line of code)


the Current event fires when you first open the form, because the focus
settles on a single record, and fires again each time you move from one
record to another. so you can lock/unlock any number of controls for the
appropriate conditions of each record.
if you want to lock control(s) in the current record after data entry is
completed, *without* moving to another record, then add the same code to the
form's AfterUpdate event *in addition to* the OnCurrent event.
 

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