How do I lock a subform?

scooble

Registered User.
Local time
Today, 05:26
Joined
Oct 25, 2010
Messages
18
I have a main form called frmSales and two subforms called frmProducts and frmService.

I have managed to lock the main form (frmSales) with;

Me.AllowEdits = False

however, how do I also lock both the subforms?

Thanks,
Tricia
 
Check (and book mark) this link for the correct syntax for referencing sub-forms and their controls.
 
Hi, thanks for the response,

I am sure the link that you posted is quite meaning ful to someone who is fluent in VBA, hwever, I am a bit of a newbie and am still having trouble understanding the syntax.

I looked at the table and tried to adapt the code, but I get an error whn I try to run the code;

Me!frmProducts.Form!SupplierCombo.Enabled = False

i.e. start from the main form, refer to the subform and then refer to the combo box and then tell it to disable...

I am sure it is completelty obvious to an expert, but for me, it look logical, but its not working.



Besides, I wanted to lock the whole subform, not all of the inndividual combo boxes - is this possibe?
 
I found an alternative solution using a completely differnt syntax which seemed to work;;
Code:
    If chkPaid = -1 Then
 
        Me.AllowEdits = False
        Form_frmProducts.AllowEdits = False
        Form_frmService.AllowEdits = False
 
        Else
        Me.Form.AllowEdits = True
        Form_frmProducts.AllowEdits = True
        Form_frmService.AllowEdits = True
 
    End If
I have a check box, which when checked locks the main form and both subforms.
it works, but not sure why?
 
I tried;

Code:
Me.frmProducts.Enabled = False

but got an error message that said;

"Compile Error:

Method or data member not found"

heyho, got it working anyway in the end.

thanks peeps
 
You could simplify that code to;
Code:
Me.Form.AllowEdits = Me.chkPaid
Form_frmProducts.AllowEdits = Me.chkPaid
Form_frmService.AllowEdits = Me.chkPaid

As a check box returns a value of -1 or true when checked and 0 or false when unchecked.
 
Last edited:
Open form (or sub form) in design view.
Select all the fields you want to lock.
Right click a field and select Properties
Go to the Data tab.
Enabled = No
Locked = Yes
 
Open form (or sub form) in design view.
Select all the fields you want to lock.
Right click a field and select Properties
Go to the Data tab.
Enabled = No
Locked = Yes

Dude I think the OP is looking for something a little more dynamic. Hence the code.
 
To be honest, I'm a little fuzzy on exactly what you're trying to do here, but there are two things you need to understand when working with a form/subform scenario.

First, the form being used as the basis for the subform actually resides on a control on the main form. That control can be locked or disabled, just like any other control on a form. Doing so prevents the user from editing the subform. You just have to remember to use the name of the subform control rather than the name of the form being used as the basis of the subform. Sometimes the two things have the same name, sometimes they don't, which may be why your code
Code:
Me.[B]frmProducts[/B].Enabled = False
bombed out. There may not be a control named frmProducts on your main form.

And secondly, if AllowEdits on the main form is set to No, the subforms, which are controls on the main form, cannot be edited either!

Linq ;0>
 

Users who are viewing this thread

Back
Top Bottom