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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I lock all records on a Form and Subform base on a checkbox 1

Status
Not open for further replies.

dennisell

Technical User
Sep 24, 2002
14
US
I have a main form called "Work Order" with 2 subforms in it. I am trying to figure out how to lock all of the fields on the forms after the work order has been filled out.

My plan was to have the user when finished filling out the forms to their satisfaction, click on a button, which would place a value in a check box named "Ready To Build". Once the value of "Yes" in in that field I would like to lock that form from future edits and deletes.
 
On the Button_OnClick() sub add all the fields that you want to lock as:
Field.Locked = True

Or on the AfterUpdate of the CheckBox, you can do the same thing.

DreamerZ
 
Thanks for the reply DreamerZ.

Is there a way that I can do the same thing (lock all of the fields) but, based on the value of the CheckBox.

When the user returns to the form to view it, the records wouldn't be locked until they clicked on the button. I don't want them changing it after my employees are processing the work order, but I do want to be able to view it.
 
Make a function that does this locking. If you really want to lock everything on the form you can just set the form's allow edit's property (and which ever others in that neighborhood that you'll need to set). If it's just some controls that need to be locked, then I would put something in the tag of all the controls that need to be locked and loop through all the controls, locking the ones with that value in the tage. That will make it less of a pain to add new controls--just put that value in the tag, and you don't have to touch the code.

Then you can fire that function from both the afterUpdate of that check box and the oncurrent of the form.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access databases since 1995.
 
Hi!

In the Form Current event procedure use this code:

If Me!YourCheckBox.Value = True then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If

hth
Jeff Bridgham
bridgham@purdue.edu
 
Jeff,

I must be doing something wrong, I placed the following code as follows:

Private Sub Form_Current()
If Me![Ready To Build].Yes = True Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If

End Sub

It doesn't seem to have an effect on anything. Any suggestions??

Thanks in advance,

Dennis Ellington
 
Hi!

Thanks for answering Jeremy! The .Value is not necessary to make the code run (Access will assume .Value) but it does make the code less ambiguous to read and trouble shoot. And it could save headaches when going to later versions. The .Value will probably not change, but getting in the habit of being specific can save a lot of time when upgrading.

hth
Jeff Bridgham
bridgham@purdue.edu
 
I hate to be a pain, but there seems to be no effect on the form when the CheckBox is checked.

This is what I have entered:

Private Sub Form_Current()
If Me![Ready To Build].Value = True Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If

End Sub

I am using Access '02 if that matters.

Thanks
 
Jeff,

Yeah, I didn't mean to malign your code. That's clearly a style issue, and it's hard to disparrage disambiguation. I just tend not to do it in that case.

Cheers,

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access databases since 1995.
 
Hi!

One more thing this code needs to be in the click event for the check box also. That way the form will be locked as soon as the box is checked.

Sorry!
Jeff Bridgham
bridgham@purdue.edu
 
I think I am almost there, the form is locking just like I hoped. I had to add a line to the code to lock the subform also. The only problem now is after entering a work order and clicking on the button to apply the value to the check box, it does lock everything, but when I close that form and proceed to open it again to enter a new work order the subform is still locked.

Here is the code I have now and the same for the on Click:

Private Sub Form_Current()
If Me![Ready To Build].Value = True Then
Me.AllowEdits = False
[Forms]![Work Order Entry sub]![Work Order Room Details sub].AllowEdits = False
Else
Me.AllowEdits = True
[Forms]![Work Order Entry sub]![Work Order Room Details sub].AllowEdits = True
End If
End Sub

Any suggestions?

Thank you
 
In the On_Open of the form, change the AllowEdits to True.

DreamerZ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top