preventing users from overwriting fields

scott51

New member
Local time
Today, 14:22
Joined
Jun 22, 2012
Messages
9
Am looking to prevent users from overwriting select fields on a form once they are input to try to keep garbage from coming in. Would like Field 1 to be set so they get a message but can overwrite if need (prevent oops, typing in wrong field errors). Field 2 I would like set so they cannot modify once it is initially input. I'm thinking this should be easy, but don't see how to do it. Help! BTW, am using Access 2010. Thanks.
 
For the second control (field), you could add some code to the On Current event of the form. You will have to check to see if the current record is a new record. If it is a new record, unlock the control otherwise lock the control.

The code would look something like this

If Me.NewRecord = True Then
Me.NameOf2ndControl.Locked = False
Else
Me.NameOf2ndControl.Locked = True
End If

Now regarding the first control (field), that is a little more difficult. What I would recommend is to have a button to allow the control to be edited otherwise keep the control locked except of course if it is a new record. You will have to utilize the On Current event of the form but also some of the events of the first control and of course the button.

I have attached a simple database with 1 table and a corresponding form that includes the code. The first name control on the form corresponds with what you want to do with your first "field". The last name control corresponds to what you want to do with your second "field".
 

Attachments

Thanks, that helps. It works for standard input fields, but not when selecting from a list box. Working on that now
 
Theoretically you should be able to lock a list box as well.

How is the list box not working?
 
After further testing, I can get it to lock the list box by putting code into the list box click or before update. However, if you click in the invoice field, you can change any fields "locked" with the code even though there is already data (invoice) in the field. Maybe I need to change the code a little where it goes off null instead of "new record".
 
If you look in the On Current event of the form of the database I provided earlier you will see the code I used. There is an IF..THEN.. ELSE..END IF statement that tests to see if the current is a new record (me.NewRecord), if it is, it sets the lock property to false.

This is where you need to add code to lock or unlock other form controls.
 
I thought the list box was locking, but I was incorrect. But I found a way around it by writing an Undo into the code on the list box before update which works great!
 
Glad to hear that you got it worked out.
 
jz

I've been trying for some time now to figure out how to prevent other users from changing certain fields once a new record has been added. No luck until I stumbled across this string earlier today. The code in your first response was absolutely spot-on for what I needed.

Woohoo!!!!
 
Glad to hear that the thread helped you out. Good luck as you move forward with your project.
 

Users who are viewing this thread

Back
Top Bottom