Re: Syntax for an open form
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Sat, 6 Aug 2005 15:51:21 -0400
"Ian Davies" <iandan.dav@xxxxxxxxxx> wrote in message
news:3E4Je.22341$Oe4.7754@xxxxxxxxxxxxxxxxxxxxxxx
> Hello
>
> I would like to include in a form load event the following
>
> Private Sub Form_Load()
>
> Dim SelSubject As String
>
> If [ACERTAIN FORM IS OPEN] Then
> SelSubject = "Like '%'"
> Else
> SelSubject = "=" & frmTests.cbdSubject.BoundText
> End If
>
>
> However, I cant find the syntax anywhere for the [ACERTAIN FORM IS OPEN]
> bit
>
> can anyone help?
If by an "open form" you mean a loaded form, you can use the following
function which returns a reference to the found form (or Nothing if the form
is not loaded).
Public Function GetForm(ByVal sFormName As String) As Form
Dim oForm As Form
For Each oForm In Forms
If StrComp(oForm.Name, sFormName, vbTextCompare) = 0 Then
Set GetForm = oForm
Exit For
End If
Next
End Function
You could modify the function to return a Boolean instead of a reference to
the form if you don't actually need the reference. It does not matter if
the form is visible or not, so that might be a criteria you'd want to add.
Also, if there could be more than 1 instance of the form loaded, you'd need
to further distinguish which instance is desired. One way you *might* do
this is by checking if the form's caption (titlebar text) contains a
particular string which uniquely identifies the instance of the form.
Another way would be to assign a unique value to the Tag property of each
instance of the form and then check the Tag (same principle as checking the
caption, but more flexible).
--
Mike
Microsoft MVP Visual Basic
.
- References:
- Syntax for an open form
- From: Ian Davies
- Syntax for an open form
- Prev by Date: Re: Syntax for an open form
- Next by Date: Re: Syntax for an open form
- Previous by thread: Re: Syntax for an open form
- Next by thread: Re: Syntax for an open form
- Index(es):
Relevant Pages
|