Hiding Sub Form Based on Value of a Field

khwaja

Registered User.
Local time
Tomorrow, 06:15
Joined
Jun 13, 2003
Messages
254
I have a main form (frmProjectsConstSM) with a sub form (frmProjectsConstSMSF). This sub form has another sub form (frmNonComp). I have a field on the frmProjectsConstSMSF. I would like to disable data entry in frmNonComp unless the field is not null. I usee the follwoing on the on current event of frmProjectsConstSMSF. But I keep hetting error. Will appreciate if someone can help me.

If IsNull(ConRefNo) Then
Me.Forms!frmProjectsConstSM!frmProjectsConstSMSF.Form!frmNonComp.Enable = False
Else
Me.Forms!frmProjectsConstSM!frmProjectsConstSMSF.Form!frmNonComp.Enable = True
End If
 
What error are you getting and at what point?

Also if you want to hide the Subform as suggested in the title of this thread use the Sub-form's Visible Property.
 
What error are you getting and at what point?

Also if you want to hide the Subform as suggested in the title of this thread use the Sub-form's Visible Property.
Not the SUBFORM's visible property but the subform CONTROL's (which houses the subform on the main form) visible property.
 
I am getting compile error on the second line. It is method or data member not found error, variable not found. I suppose I could hide the form but that would leave the tab blank, so I thought disabling it will be a better option.
 
I am getting compole error on the second line. It is method or data member not found error, variable not found. I suppose I could hide the form but that would leave the tab blank, so I thought disabling it will be a better option.
You need to refer to the control on the sub form which houses the sub sub form (not the sub subform itself unless they share the exact same name). Also, you are using ME wrong. You don't use Forms! with ME. You should have something like this:

Code:
Me.Controls("frmNonComp"),Form.Controls("frmNonComp").Visible = Not (IsNull(Me.ConRefNo))

That also gets rid of the IF and takes it down to one line.
 
I'm not sure if this is an error in your actual code or just in the code posted here, but you have a space in part of the form name at the Red underscore;
Code:
If IsNull(ConRefNo) Then
Me.Forms!frmProjectsConstSM!frmProjectsConstSMSF.F[B][COLOR="Red"]_[/COLOR][/B]orm!frmNonComp.Enable = False
Else
Me.Forms!frmProjectsConstSM!frmProjectsConstSMSF.F[B][COLOR="Red"]_[/COLOR][/B]orm!frmNonComp.Enable = True
End If
 
Not the SUBFORM's visible property but the subform CONTROL's (which houses the subform on the main form) visible property.
Code:
Dim X as Integer
X = 0
While X < 1000
     Write by hand "I must be more careful and specific"
     X = X +1
Wend
 
Code:
Dim X as Integer
X = 0
While X < 1000
     Write by hand "I must be more careful and specific"
     X = X +1
Wend
Yep, P - and you also overlooked (like I did originally) the Me.Forms! part which is not right either.
 
I tried following in the on current event of frmProjectsConstSMSF but I still get the compile error : invalid use of property and it selects me.controls.

Me.Controls ("frmNonComp"), Form.Controls("frmNonComp").Visible = Not (IsNull(Me.ConRefNo))
 
I tried following in the on current event of frmProjectsConstSMSF but I still get the compile error : invalid use of property and it selects me.controls.

Me.Controls ("frmNonComp"), Form.Controls("frmNonComp").Visible = Not (IsNull(Me.ConRefNo))
Possibly because you still don't have the correct syntax. You have a comma and space where it shouldn't be neither. (sorry about the comma - I don't know how I got a comma where a period should be)

It is:
Code:
Me.Controls("frmNonComp")[B][COLOR=red].[/COLOR][/B]Form.Controls("frmNonComp").Visible = Not (IsNull(Me.ConRefNo))
 
Thanks Bob. I have mended it but looks like the reference to form is treated as field because I am now getting an error that '.. can't find field 'frmNonCom' referrered to in your expression.

Just to be clear ConRefNo field is what we are testing against and that is sitting in the sub form frmProjectsConstSMSF, whereas frmNonComp is the sub form of frmProjectsConstSMSF.
 
Thanks Bob. I have mended it but looks like the reference to form is treated as field because I am now getting an error that '.. can't find field 'frmNonCom' referrered to in your expression.

Just to be clear ConRefNo field is what we are testing against and that is sitting in the sub form frmProjectsConstSMSF, whereas frmNonComp is the sub form of frmProjectsConstSMSF.
AGAIN I will tell you - You have to refer to the CONTROL NAME not the SUBFORM name. Check to see what the subform control name is for both subforms. You need to use those and NOT the names of the subforms unless they share the exact same name.

See my tutorial on Subforms here and pay attention to the screenshot which shows you what I'm talking about with the subform control/container.
 
Thanks Bob. A very nicely written tutorial. As I understand now, I have main form (A), the field I am testing against is in the sub form (B)and I am merely trying to make the sub sub form container (C) to be disabled based on the status of field on form B. If my code resides on form B, then do I need to refer to two controls - one for the field I am testing and the other for the container. But if I am referring to the form 3 property, would I still be referring to the container or do I have to name the form? bY the way I have same name for the container and the form.
 
Yes, you would be referring to the control for both subforms as you move down the line.
 

Users who are viewing this thread

Back
Top Bottom