Disabling a subform.

P

Proko

Not sure if this is the best method to do this so any help would be
appreciated. I have a form with a subform that is used for data edits and
data entry. When the main form opens I want to check if we are in edit mode
or new record mode by checking if the mainform autonumber field, ID, is null.
If ID is not null then no problem. But if it is null then I want to disable
the subform so that the user cannot start entering data into it. I want the
subform to be disabled until the user enters something on the mainform to
generate an ID number.
On the 'on current' event of the mainform I have:
If IsNull(ID) then
Me!Sub_MaterialList.Form.Enabled = False
End if
When the form is opened in edit mode I get a run-time error 2465 message.
Is my syntax wrong or is it impossible to set a subform's enabled property
to false?
Is there a better way of doing this?
 
A

Arvin Meyer [MVP]

You need to enable the subform when the form is opened in edit mode. Instead
of checking whether the ID is null, you might try checking if it's a new
record, then enable the subform when the first character is typed:

Sub Form_Dirty(Cancel As Integer)
Me!Sub_MaterialList.Form.Enabled = True
End Sub
 
R

Rob Ward

Don't know about the rest, but you don't need the keyword 'form' in your
syntax; its should be


Me!Sub_MaterialList.Enabled = False

The 'form' keyword is used when you want to access a control or property of
the form within the subform, not the subform control itself.
 
D

Dirk Goldgar

Proko said:
Not sure if this is the best method to do this so any help would be
appreciated. I have a form with a subform that is used for data edits and
data entry. When the main form opens I want to check if we are in edit
mode
or new record mode by checking if the mainform autonumber field, ID, is
null.
If ID is not null then no problem. But if it is null then I want to
disable
the subform so that the user cannot start entering data into it. I want
the
subform to be disabled until the user enters something on the mainform to
generate an ID number.
On the 'on current' event of the mainform I have:
If IsNull(ID) then
Me!Sub_MaterialList.Form.Enabled = False
End if
When the form is opened in edit mode I get a run-time error 2465 message.
Is my syntax wrong or is it impossible to set a subform's enabled property
to false?
Is there a better way of doing this?


I think your syntax is wrong, since it's the subform control you want to
disable, not the form object it displays. If "Sub_MaterialList" is really
the name of the subform control (not just the name of its source object),
then this should work:

Me!Sub_MaterialList.Enabled = Not IsNull(Me!ID)

However, error 2465 is a field-not-found error, isn't it? To me, that
suggests that the name of the subform control may not be "Sub_MaterialList"
at all. I would check that and amend the above line of code accordingly.

Presumably you have code in the form's Dirty event or some such place to
enable the subform control after the user has entered something on the main
form.

I usually use code in the subform control's Enter event to ensure that the
necessary fields have been filled out on the main form. If not, I display a
message and set the focus back to the required fields.
 
E

Evi

Dirk Goldgar said:
I think your syntax is wrong, since it's the subform control you want to
disable, not the form object it displays. If "Sub_MaterialList" is really
the name of the subform control (not just the name of its source object),
then this should work:

Me!Sub_MaterialList.Enabled = Not IsNull(Me!ID)

However, error 2465 is a field-not-found error, isn't it? To me, that
suggests that the name of the subform control may not be "Sub_MaterialList"
at all. I would check that and amend the above line of code accordingly.

Presumably you have code in the form's Dirty event or some such place to
enable the subform control after the user has entered something on the main
form.

I usually use code in the subform control's Enter event to ensure that the
necessary fields have been filled out on the main form. If not, I display a
message and set the focus back to the required fields.

To check the subform's name (which may not be the one in the database
window) open the main form in Design view, click on the subform, go to
Properties and the Other tab.
Evi
 
D

Dirk Goldgar

Arvin Meyer said:
Sub_MaterialList is the name of a subform control. The control has a form
property that should be addressed, although I supposed it is possible to
refer to the control itself.


I have to disagree with you on this one, Arvin. A form has no Enabled
property. In this case, the OP wants to enable or disable the subform, and
that is a property of the subform control, not the form object it displays.
 
A

Arvin Meyer [MVP]

Dirk Goldgar said:
I have to disagree with you on this one, Arvin. A form has no Enabled
property. In this case, the OP wants to enable or disable the subform,
and that is a property of the subform control, not the form object it
displays.

Looks like you are correct on this one. It's the control that's enabled.
 

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

Similar Threads


Top