[AccessD] How do I tell if a form is opened as a subform or not?

Andy Lacey andy at minstersystems.co.uk
Thu Mar 13 16:57:19 CST 2003


By mistake sent this direct to Gustav earlier. Meant to come here.
Apologies to Gustav for getting it twice

I have a form which is used both as a subform and on its own. It saved
having two almost identical forms. One of the differences I wanted
though was to have a footer section witha Quit button when opened on its
own, but not when it's a subform. My solution was very low-tech. When
I'm opening it on its own I just open it with something identifiable in
OpenArgs and test that. If nothing in OpenArgs it's a subform, else it
isn't. If it isn't then I make my otherwise invisible footer section
visible. Not sure how it would react to Drew's hypothetical situation
but unless you're likely to do that it could perhaps stay hypothetical.

Andy Lacey
http://www.minstersystems.co.uk



> -----Original Message-----
> From: accessd-admin at databaseadvisors.com 
> [mailto:accessd-admin at databaseadvisors.com] On Behalf Of Drew Wutka
> Sent: 12 March 2003 22:22
> To: 'accessd at databaseadvisors.com'
> Subject: RE: [AccessD] How do I tell if a form is opened as a 
> subform or not?
> 
> 
> I know what you are saying about intentionally looking for an 
> error.  It gives me an uneasy feeling too, but there are some 
> things that just absolutely require it.
> 
> As far as your code, I'm pretty tired so I could be wrong on 
> this, but I think I could trigger a false positive with your 
> code.  If you opened formA, then opened formB, then set the 
> source object on a subform on FormA to FormB, you will now 
> have FormB as a subform on FormA, but your function will say 
> False, because FormB was the last form to be put into the 
> form's collection AND it is also now a subform.  (Actually, 
> just tried it, and it did say false from the subform)
> 
> I know, it wouldn't be a common occurrence, but the error 
> method is guaranteed to be correct.
> 
> Drew
> 
> -----Original Message-----
> From: Gustav Brock [mailto:gustav at cactus.dk]
> Sent: Wednesday, March 12, 2003 1:17 PM
> To: Drew Wutka
> Subject: Re: [AccessD] How do I tell if a form is opened as a 
> subform or not?
> 
> 
> Hi Drew
> 
> I don't like at all coding where you rely on error 
> generation. It may very well be quick and dirty code and some 
> like that, but I try to use it as the last resort only.
> 
> Previously I have posted this small function for the same 
> purpose - it could have been for the benefit of Arthur "the 
> static lover" as you'll see. It is not much larger than your code:
> 
> <code>
> 
> Private Function IsSubform() As Boolean
> 
>   Static booSubform     As Boolean
>   Static lngFormsCount  As Long
> 
>   If lngFormsCount = 0 Then
>     lngFormsCount = Forms.Count
>     booSubform = StrComp(Forms(lngFormsCount - 1).Name, Me.Name,
> vbTextCompare)
>   End If
> 
>   IsSubform = booSubform
>       
> End Function
> 
> </code>
> 
> /gustav
> 
> 
> > I know, it's just one of my coding habits.  I only use 
> 'resume next' 
> > when
> I
> > want to completely ignore errors.  If I am expecting an 
> error...to use 
> > it (as in my example), or I am just handling unexpected 
> errors, then I 
> > always use On Error Goto...
> 
> > Make sense?  (your code is smaller....can't deny that!<grin>)
> 
> > Drew
> 
> > -----Original Message-----
> > From: Gustav Brock [mailto:gustav at cactus.dk]
> > Sent: Wednesday, March 12, 2003 11:13 AM
> > To: Drew Wutka
> > Subject: Re: [AccessD] How do I tell if a form is opened as 
> a subform 
> > or not?
> 
> 
> > Hi Drew
> 
> > That was an awful lot of code to replace something like these two
> > lines:
> 
> > <code>
> 
> > Private Function IsSubform() As Boolean
> 
> >   On Error Resume Next
> >   IsSubform = Me.Parent.hWnd
>     
> > End Function
> 
> > </code>
> 
> > /gustav
> 
> 
> >> This is from my new MiniCalendar database....still in 
> >> development...but
> > the
> >> function works fine.
> 
> >> Private Function AmIASubForm() As Boolean
> >> On Error GoTo ErrorHandler
> >> Dim varTemp
> >> varTemp = Me.Parent
> >> AmIASubForm = True
> >> Exit Function
> >> ErrorHandler:
> >> Err.Clear
> >> AmIASubForm = False
> >> End Function
> 
> >> -----Original Message-----
> >> From: Bruce Bruen [mailto:bbruen at bigpond.com]
> >> Sent: Tuesday, March 11, 2003 6:58 PM
> >> To: AccessD
> >> Subject: [AccessD] How do I tell if a form is opened as a 
> subform or 
> >> not?
> 
> 
> >> Hi List,
> 
> >> I am trying to use a form that may appear as a subform or 
> on its own. 
> >> If it's a subform then I want to maximise it in its parent control 
> >> space, if not then it should be sized to fit the form. But 
> how do I 
> >> tell where it is being opened?  The following doesn't work:
> 
> >>     On Error Resume Next
> >>     If Not IsNull(Me.Parent.Name) Then
> >>         boolIsSubform = True
> >>         DoCmd.Maximize
> >>     Else
> >>         boolIsSubform = False
> >>     End If
> >>     On Error GoTo 0
> 
> >> Ignore the fact that the docmd works on the parent, I am 
> not worried 
> >> about that at the moment, only that I don't know how to test the 
> >> "subformedness".
> 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com 
> http://databaseadvisors.com/mailman/listinfo/a> ccessd
> Website: 
> http://www.databaseadvisors.com 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com 
> http://databaseadvisors.com/mailman/listinfo/a> ccessd
> Website: 
> http://www.databaseadvisors.com
> 




More information about the AccessD mailing list