Lock current record only

Archie999

Access Wannabee
Local time
Today, 08:13
Joined
May 25, 2003
Messages
45
Hi,

I have a form that contains information that once entered, would not likely need to be edited. I would like to have a checkbox to enable/disable edits to the form to prevent accidental editing by, say, novice users.

I got the record to lock by adding the following code to a) the after update event of my enable_edit checkbox and b) the on_current event of the form.

If Me!ChkEnable_Edit.Value = True Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End If

The problem is that when the form is locked, so is my checkbox! Is there someway I can exclude the checkbox? Or do I need to individaully deal with each control on my form?

Also, if anyone has a better way to accomplish my ultimate goal then please advise. Thanks in advance.

Arch
 
Rather than using a checkbox, just lock all records in the current event. Then have a button that unlocks the form.
 
Oops... I see Pat beat me to the punch but I will leave this anyway...

Set the forms Allow Edits property to False. In the forms On Current event:

If Me.NewRecord Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End if

You can add a command button to change the AllowEdits to True if you need to edit the record. You can hide the button if you like.

That is just one possible approach....

hth,
Jack
 
Almost got it!

Thanks Pat and Jack for your responses. That did the trick except for one minor side effect...

The config you mentioned also locked my subform, which is fine but the button I created to unlock the form does not unlock the subform so I am unable to insert records into my subform.

It is not important whether the subform is initially locked or not, but obviously I need to be able to unlock it. I checked the properties for the subform and it is set to allow edits. I tried to add another button that one could click to insert a record into the subform but I'm afraid I'm too much a novice at VB to pull it off. Searched around the forum for answers but did not get any hits yet.

Do you have any suggestions? Thanks again!

Arch
 
Try this:

Me.AllowEdits = True
Me.SubformControlName.Form.AllowEdits = True

This code can go in the one button.

hth,
Jack
 
Thanks!

Hi Jack,

Yup, that did it.

I also added: Me.SubformControlName.Form.AllowAdditions = True

so I could add as well as edit records in the subform.

Thanks again.
 
You are welcome. Continued success with your project...

Jack
 

Users who are viewing this thread

Back
Top Bottom