Lock Down a field on a form after data has been entered

G

Guest

Can I lock down a field on a form once data has been entered into that field?
I want the user (or a macro that is gong to set a value) to enter data but
then I don't want them to be able to alter it. Is this possible?
 
G

Guest

Hi Gretchen,

If the user updates the field, you could have it in the after update event
so that it locks the field like this:

me.FIELDNAME.locked = true

If you never want people to be able to edit data in any field, you could set
AllowEdits to False for the form.

If it's random fields, remember to also check in the On Current event
whether the fields should be enabled or not...

Hope this helps.

Damian.
 
G

Guest

Damian,
Thanks for your help. The code however did not stop me from changing the
field after I updated it. Here is my code:

Private Sub Client_Name_AfterUpdate()
Me.[Client Name].Locked = True
End Sub

To test it I filled in my Client Name field then went back to it and typed
over it. It let me and it saved my new name. Did I miss a step?
Thanks,
Gretchen
 
R

Ron2006

In the oncurrent event for the form

if isnull(Me.[Client Name]) then
Me.[Client Name].locked = false
else
Me.[Client Name].locked = true
endif.


Now my question is: If you make a mistake, how will it ever get fixed.

A further note. This will stop the user from entering data in that
field on that form. However, code somewhere else on the form can change
the data even though the field is locked.

Ron
 
G

Guest

Thanks for your help Ron...the code worked fine althrough I had to put it on
the
on exit as there was no on current event for that field.

The data is being automatically populated from a form that the user starts
on. There are queries that link the two fields together but the queries are
not working because people are inadvertantly changing the Client Name field.
I think this should take care of the problem.

What do you mean about code in other parts of the form that would allow a
change to this field? Are you refering to using the table and field in a
different form?

Thanks again.
 
R

Ron2006

Gretchen,

The OnCurrent event is the OnCurrent event for the Form not the field.

What do you mean about code in other parts of the form that would allow a
change to this field? Are you refering to using the table and field in a
different form?

Sometimes it is good to have a field that you do not want the user to
update individually but do want them to be able to see and update but
through a controled means. I have seen this done relative to a date.
The designer wanted to date to ALWAYS be updated via a calendar.
Consequently, the field on the form was locked BUT if the user double
clicked on the date it would go to a calendar form that allowed them to
change it, in which case the date was changable.

Or for instance maybe the field is the last changed date for a record.
The field is locked so that the user cannot change the field directly
however if they change some other field on the form, then the after
update event of that changed field puts date() into this last changed
date.


Ron
 

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


Top