Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field can't be modified after initial insert 1

Status
Not open for further replies.

nexus

Programmer
Jun 16, 1999
28
0
0
CA
I'm not sure if there's some function in VBA that let's you specifically prevent updates on certain fields, or if I have to put some code behind the field. Once the user inserts a value in the field, he shouldn't be able to change that value. However, deleting and re-entering the record is acceptable. Any suggestions would be much appreciated.
 
Yes to do it on the fly you need VBA code.<br>
<br>
Private Sub Text0_AfterUpdate()<br>
Text0.Enabled = False<br>
OR<br>
Text0.Locked = False<br>
End Sub<br>
<br>
Use one or the other but not both.<br>

 
I know you asked about code, but just to throw in a couple of alternatives that don't require code: The add-and-delete-but-not update restriction can be applied on the form level using the data property AllowEdits=No. If you wanted this to apply to only some fields on the form you'd have to segregate them into a subform on that main form. If the restricted fields are all in the dame table you can use Access security.
 
Thanks for the help. If I try locking it in code, it locks ALL the fields on the form, and I can't enter new records. I'm pretty sure the subform idea would work, but I won't be able to implement it until I get some sort of approval.<br>
<br>
I like the locking idea, but is there any way to make it lock the specific field for a specific record?
 
Re: Doug P's code, for text0 are you substitutiong your form's name instead of your textbox's name? The latter would lock the whole form. Also you may need to unlock those fields again when you go to a new record, open the form, etc. You could use the OnCurrent event of the form to lock or unlock the field depending on whether or not the field has a value in it, as well as the form's AfterUpdate.<br>
<br>
BTW, preventing a user from updating a field in a form does not prevent them from updating that field in another form, or directly in the table, or via a query.
 
I got it! used the GotFocus Event of the field and said if the value isn't null, lock it, else unlock it. THANKS GUYS!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top