Lock/unlock form AND subforms from editing data

cmray58

Registered User.
Local time
Today, 15:48
Joined
Mar 24, 2014
Messages
70
Hello,

I have a form with several subforms within (tabbed subforms). I've used the code:

In the Current event of the parent form -
Code:
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = False
In the Current event of each of the subforms -
Code: (THIS NEVER WORKS FOR ME - RUNTIME ERROR)
Me.AllowEdits = Me.Parent.AllowEdits
Me.AllowDeletions = Me.Parent.AllowDeletions
Me.AllowAdditions = Me.Parent.AllowAdditions
In the Click event of the button -
Code:
Me.AllowEdits = True
Me.AllowDeletions = True
Me.AllowAdditions = True

so the main form is locked upon opening and unlocked with the click of an unlock button.

The problem is, I don't know how to apply this to the subforms as well. They just stayed unlocked the whole time.
 
In the Current event of each of the subforms -
Code: (THIS NEVER WORKS FOR ME - RUNTIME ERROR)
Me.AllowEdits = Me.Parent.AllowEdits
Me.AllowDeletions = Me.Parent.AllowDeletions
Me.AllowAdditions = Me.Parent.AllowAdditions
What error number and description do you get?
Maybe post a stripped version of your database with sample date, zip it because you haven't post 10 post yet.
 
What error number and description do you get?
Maybe post a stripped version of your database with sample date, zip it because you haven't post 10 post yet.

runtime error 2452 the expression you entered has an invalid reference to the parent property

I don't have access to the file right now, but will later if you still need more
 
I've the below code in a subform current event, and it runs without error, do you use nested subform or have the subform placed on other controls, so that the Me.Parent is not pointing to the main form?
Code:
Me.AllowEdits = Me.Parent.AllowEdits
 
I've the below code in a subform current event, and it runs without error, do you use nested subform or have the subform placed on other controls, so that the Me.Parent is not pointing to the main form?
Code:
Me.AllowEdits = Me.Parent.AllowEdits

I'm honestly not sure. How can I check this? In the meantime, I'm going to try your code.
 
The code is the same as yours!
Put the form in design view, look if the subform is placed on another control.
If you still can't get it, I think the best is when you post the database as described in one of my former post.
 
I'm not sure what you mean by "placed on another control." Let me try to paste, hold on.
 
I also don't know how to post a stripped version of the database like you're asking, hah. God I'm so incompetent with this.
 
Try to amend lock/unlock to all sub forms
 
If you zip the database and the size is below 2MB you don't need to strip it, else make a copy of the database, remove all unnecessary (Reports/Queries/Forms/Tables), until the zip size is below 2MB.
 
I've stripped it of all records (for confidentiality purposes, of course) but I've left everything else alone.
 

Attachments

Na - is it the same form as you showed on a former picture, because there was no button on the main form?

I add a button put in some code, but I can not reproduce the error you got.
The database is attached.
 

Attachments

Na - is it the same form as you showed on a former picture, because there was no button on the main form?

I add a button put in some code, but I can not reproduce the error you got.
The database is attached.

I just checked your database out. The button you added is opposite of what I've been working on. I want the form to be locked BY DEFAULT and have an Unlock button for when someone wants to edit an entry. However, you did get the subforms to listen, so that's awesome.
 
Also, still getting that error: "Run-time error 2452: The expression you entered has an invalid reference to the parent property." when opening the subforms manually from the navigation panel.
 
I just checked your database out. The button you added is opposite of what I've been working on. I want the form to be locked BY DEFAULT and have an Unlock button for when someone wants to edit an entry.
Then open the main form in design view and lock it and save it, it shouldn't be such a big deal to complain about. :(
Also, still getting that error: "Run-time error 2452: The expression you entered has an invalid reference to the parent property." when opening the subforms manually from the navigation panel.
Yes ofcause - when the form is open alone, then it has NO parent. You never mention it should be open alone, the whole thread was about a main/sub form. :mad:
 
Then open the main form in design view and lock it and save it, it shouldn't be such a big deal to complain about. :(

Yes ofcause - when the form is open alone, then it has NO parent. You never mention it should be open alone, the whole thread was about a main/sub form. :mad:

Sorry, but it used to give me the error when opening on the main form as well. I didn't know that it will always give me the error when opening the subform separately; that's fine. Thanks for the help..
 
Also, I was at no point complaining for the record. Clarifying what I was looking for. Thanks again for the help.
 
Okay, I've literally copied the coding from the file you attached in here and now for some reason in my database the sub-forms are showing up blank..
 

Attachments

Users who are viewing this thread

Back
Top Bottom