|
|
I've seen the code in other posts to hide a subform based on a value of a combo box on a main form or the value of a field on the main form, but I need to hide/show a subform based on the value of a field in the subform, itself. Is that possible?
I tried the following, but it did not work:
Me.frmParentCode.Visible = (Me.frmParentCode!LogName Is Not Null)
where "frmParentCode" is my subform and "LogName" is the field to evaluate. If LogName is Null, I want to hide the subform and if it is Not Null, I want to show the subform. My main form name is "frmProcess"
Thanks for any help you can offer! Susan
|
|
well, first you need to make sure that frmParentCode is the name of the *subform control* within the mainform that "holds" or "contains" the subform object. to get that name, open the mainform in Design view, click *once* on the subform within the mainform to select it, open the Properties box, click on the Other tab and look at the Name property. once you're using the correct subform control name, try the following code, as
Me!SubformControlName.Visible = Not IsNull(Me!SubformControlName.Form!LogName)
the above goes all on one line, regardless of linewrap in this post. replace SubformControlName with the name that you've verified as correct, of course.
hth
"Susan" <Susan[ at ]discussions.microsoft.com> wrote in message news:78F9CEB0-4CB5-4F30-91EF-8A7E3387827D[ at ]microsoft.com...
[Quoted Text] > I've seen the code in other posts to hide a subform based on a value of a > combo box on a main form or the value of a field on the main form, but I
need > to hide/show a subform based on the value of a field in the subform, itself. > Is that possible? > > I tried the following, but it did not work: > > Me.frmParentCode.Visible = (Me.frmParentCode!LogName Is Not Null) > > where "frmParentCode" is my subform and "LogName" is the field to evaluate. > If LogName is Null, I want to hide the subform and if it is Not Null, I want > to show the subform. My main form name is "frmProcess" > > Thanks for any help you can offer! > Susan
|
|
OK, thanks!! I verified the actual name of my subform is frmParentCode. I tried this in the "On Load" of the main form and it doesn't work...the subform always shows. I also tried it in the "On Load" of the subform and I get a Run-time error '2465' that says it can't find the field 'frmParentCode' referred to in my expression.
Sorry to be so dumb, but can you please tell me specifically where I need to put this?
THANKS!!! Susan
"tina" wrote:
[Quoted Text] > well, first you need to make sure that frmParentCode is the name of the > *subform control* within the mainform that "holds" or "contains" the subform > object. to get that name, open the mainform in Design view, click *once* on > the subform within the mainform to select it, open the Properties box, click > on the Other tab and look at the Name property. once you're using the > correct subform control name, try the following code, as > > Me!SubformControlName.Visible = Not > IsNull(Me!SubformControlName.Form!LogName) > > the above goes all on one line, regardless of linewrap in this post. replace > SubformControlName with the name that you've verified as correct, of course. > > hth > > > "Susan" <Susan[ at ]discussions.microsoft.com> wrote in message > news:78F9CEB0-4CB5-4F30-91EF-8A7E3387827D[ at ]microsoft.com... > > I've seen the code in other posts to hide a subform based on a value of a > > combo box on a main form or the value of a field on the main form, but I > need > > to hide/show a subform based on the value of a field in the subform, > itself. > > Is that possible? > > > > I tried the following, but it did not work: > > > > Me.frmParentCode.Visible = (Me.frmParentCode!LogName Is Not Null) > > > > where "frmParentCode" is my subform and "LogName" is the field to > evaluate. > > If LogName is Null, I want to hide the subform and if it is Not Null, I > want > > to show the subform. My main form name is "frmProcess" > > > > Thanks for any help you can offer! > > Susan > > >
|
|
no, it won't run in the subform, because the subform loads before the mainform, and you're actually trying to hide a control in the mainform (the subform control). seems like it should run in the mainform's Load event, unless 1) the subform control's SourceObject is assigned after the Visible/Not Visible code runs, or 2) the subform object's RecordSource is assigned after the Visible/Not Visible code runs. if neither 1) or 2) is the case, then have you checked the value of field LogName? it may be a zero-length string, rather then being Null. try the following, as
Dim ctl As Control
set ctl = Me!SubformControlName.Form!LogName
Me!SubformControlName.Visible = Not (IsNull(ctl) Or Len(ctl & "") = 0)
and btw, if the zero-lenth string turns out to be the issue, suggest you open the *table* in Design view and set field LogName's AllowZeroLengthString property to No. for more information, see http://home.att.net/~california.db/tips.html#aTip9.
hth
"Susan" <Susan[ at ]discussions.microsoft.com> wrote in message news:14BD75AB-B13E-4DA9-9D7D-06A10FC02841[ at ]microsoft.com...
[Quoted Text] > OK, thanks!! I verified the actual name of my subform is frmParentCode.
I > tried this in the "On Load" of the main form and it doesn't work...the > subform always shows. I also tried it in the "On Load" of the subform and I > get a Run-time error '2465' that says it can't find the field 'frmParentCode' > referred to in my expression. > > Sorry to be so dumb, but can you please tell me specifically where I need to > put this? > > THANKS!!! > Susan > > "tina" wrote: > > > well, first you need to make sure that frmParentCode is the name of the > > *subform control* within the mainform that "holds" or "contains" the subform > > object. to get that name, open the mainform in Design view, click *once* on > > the subform within the mainform to select it, open the Properties box, click > > on the Other tab and look at the Name property. once you're using the > > correct subform control name, try the following code, as > > > > Me!SubformControlName.Visible = Not > > IsNull(Me!SubformControlName.Form!LogName) > > > > the above goes all on one line, regardless of linewrap in this post. replace > > SubformControlName with the name that you've verified as correct, of course. > > > > hth > > > > > > "Susan" <Susan[ at ]discussions.microsoft.com> wrote in message > > news:78F9CEB0-4CB5-4F30-91EF-8A7E3387827D[ at ]microsoft.com... > > > I've seen the code in other posts to hide a subform based on a value of a > > > combo box on a main form or the value of a field on the main form, but I > > need > > > to hide/show a subform based on the value of a field in the subform, > > itself. > > > Is that possible? > > > > > > I tried the following, but it did not work: > > > > > > Me.frmParentCode.Visible = (Me.frmParentCode!LogName Is Not Null) > > > > > > where "frmParentCode" is my subform and "LogName" is the field to > > evaluate. > > > If LogName is Null, I want to hide the subform and if it is Not Null, I > > want > > > to show the subform. My main form name is "frmProcess" > > > > > > Thanks for any help you can offer! > > > Susan > > > > > >
|
|
|