How to lock a field in a form

maperou

Registered User.
Local time
Today, 13:14
Joined
Jun 23, 2014
Messages
10
Is it possible to lock a field in a form after the user has populated the field? So for example, I have two date fields and I want them to be locked after the user has entered values on those fields. I want to avoid the user to come back in the future and change those fields. However I would like the database administrator to be able to change those dates when needed. How do I do this?
Thank you in advance.
 
You can also try putting the following psuedocode (change names to suit) in the form openevent and the control lost focus event
Code:
mycontrol.locked=currentuser<>supervisor and nz(mycontrol)<>""
 
Thank you CJ London. Apologies I'm not an expert in VBA. I can understand the logic but not write it, so I'm really a diaper VBA user. Appreciate it if you could please explain what this code is trying to achieve and what nz means.

Just a little history here. I took over a database that has some coding in it. So I'm trying to decipher the code that is already in this database. The database has an Administrator table where levels are defined, thus level 4 is used for the Administrator. So based on this, is the below correct in terms of what you suggested and what would this do?

Private Sub txtdtStart_LostFocus()

mycontrol.locked=iAuthLevel <=3 and nz(mycontrol) <>""

End Sub

Your help is greatly appreciated! Thank you!
 
Do they have to see the field after input?

If not try this:

Private sub nameoffield_AfterUpdate()

Me.fieldname.Visible = False

End Sub



-------------------------------------------------------------------
REMEMBER
Give us a thanks that gets us a long way if we helped you!
 
here is a link to explain what the nz function does

http://office.microsoft.com/en-gb/access-help/nz-function-HA001228890.aspx

I suggest using it because your control could have a null value

Assuming the field you want to lock is called txtdtStart

then your code should be

Code:
txtdtStart.locked=iAuthLevel <=3 and nz(txtdtStart) <>""

Don't forget to also put it in the form open event
 
Thank you CT2013. Unfortunately yes they do have to see the field that is date field (start date). Would this code make the field invisible?
 

Users who are viewing this thread

Back
Top Bottom