Trying to disable subform (and have read webpage on subform property referencing)

R

rgrantz

I have a main form with a subform, and in that subform is another subform
(3rd form is linked to 2nd form, 2nd form is linked to main form)

I am trying to, when the user opens the main form, check for a zero-length
string (null value, but it's a text field, which I believe does not support
a null value check) in the subform, and if it is IS zero length, completely
disable the 3rd form (the subform of the subform).

I have put the code in the OnLoad event of the Main form, and have tried:

If Me!Subform1.Form.ControlName.Value Is Null Then
Me!Subform1.Form!Subform2.Form.Visible = False
Else
Me!Subform1.Form!Subform2.Form.Visible = True
End If

I have also tried:


If Me!Subform1.Form.ControlName.Value = "" Then
Me!Subform1.Form!Subform2.Form.Visible = False
Else
Me!Subform1.Form!Subform2.Form.Visible = True
End If


And also

If Me!Subform1.Form.ControlName = "" Then
Me!Subform1.Form!Subform2.Form.Visible = False
Else
Me!Subform1.Form!Subform2.Form.Visible = True
End If

I have also tried moving the sub to different events (ie. setting focus to
the Subform control upon loading the main form (which works), and then using
the GotFocus and LostFocus events to change the visibility or enabling of
the sub-subform. Nothing seems to be working.

My goal here is to, when the Subform's control is blank (ie. new record),
then the sub-subform (the subform's subform) isn't enabled until the subform
control has a value in it.

Is there a way to do this?

Thanks for any help.
 
T

tina

i think your problem is that you're trying to set the Visible property of
the form object (of the sub-subform). instead, set the Visible property of
the sub_subform CONTROL. remember, a subform object sits in a "box" - a
control - on the parent form. that control has many properties that are
identical to any other control, such as a textbox or combo box. and one of
those is the Visible property.

first, get the Name of the sub_subform control. *it may not be the same as
the Name of the sub-subform form object.* to get the correct name, open the
subform in design view. click on the sub-subform ONCE, to select it. in the
Properties box, click on the Other tab, and look at the Name property.
that's the name of the sub-subform control.

i would suggest putting the following code in the OnCurrent event of the
subform form object, and in the AfterUpdate event of the subform text
control that you're testing for a value, as

Me!Sub-SubformControlName.Visible = Not
IsNull(Me!SubformTextControlName)

substitute the correct names, of course.
btw, an empty string variable in VBA has a value of "", if i recall
correctly. but a Text datatype field in a table can be Null, or its' value
may be a zero-length string IF the field's AllowZeroLength property in the
table is set to Yes (which i wouldn't recommend doing, most of the time).

hth
 
R

rgrantz

That totally did it, and I thank you very much.

I'm assuming from the syntax here that the Null check (Not is null) returns
a 0 or a 1 (or -1), substituting for the True/False value one usually uses
with .visible? I was not familiar with this approach, and it opens a world
of possibilities for a newb like myself, thanks again.
 
T

tina

well, True/False *is* -1/0. the words are just a handy translation that the
system gives us. the following expression would work just like the one i
gave you:

If IsNull(Me!SubformTextControlName) Then
Me!Sub-SubformControlName.Visible = 0
Else
Me!Sub-SubformControlName.Visible = -1
End If

putting the expression on the "right side" of the equals statement, and in
this case negating the return value with 'Not', is a handy little trick
that's very useful for toggling True/False or On/Off property settings
instead of the much longer If statement - and i learned it right here in the
newsgroups! :)
 

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

Top