Lock on save

J

JenK

I would like to have a save record button on my form, that, when pressed will
save the record and lock it from changes. I want this because I have users
constantly overwritting compnay names, adresses and so on. can anyone help me
with coding of this. I am using both macros and coding.
 
R

Ryan

I accomplish this by adding an column in my table called lockout and make it
a yes/no datatype and set its default value to true. Then I add this code to
the form.

Private Sub Form_Load()
If Me.Lockout = True Then
Me.AllowEdits = False
End If
End Sub
 
A

Allen Browne

Open the form in design view, and set its AllowEdits property to No, leaving
AllowAdditions as Yes. You can now enter new records, and view (but not
edit) existing ones. You probably want to set AllowAdditions to No as well.

If you do want the user to be able to unlock the form for editing (i.e. you
just want to reduce accidental changes), see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

Download the example, and paste into your database. (This is copy'n'paste
stuff.)
 
L

Linq Adams via AccessMonster.com

You could do this, repeating the line of code for each textbox you want
locked, if the textbox is populated:

Private Sub Form_Current()
CompanyName.Locked = Not IsNull(Me.CompanyName)
End Sub

Or you could simply loop thru all textboxes, locking the populated ones.


Private Sub Form_Current()
Dim ctrl As Control

For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If Not IsNull(ctrl.Value) Then
ctrl.Locked = True
Else
ctrl.Locked = False
End If
End If
Next
End Sub
 
R

Rice via AccessMonster.com

Thanks, I'll try it!

Linq said:
You could do this, repeating the line of code for each textbox you want
locked, if the textbox is populated:

Private Sub Form_Current()
CompanyName.Locked = Not IsNull(Me.CompanyName)
End Sub

Or you could simply loop thru all textboxes, locking the populated ones.

Private Sub Form_Current()
Dim ctrl As Control

For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If Not IsNull(ctrl.Value) Then
ctrl.Locked = True
Else
ctrl.Locked = False
End If
End If
Next
End Sub
 

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