Re: Syntax for an open form

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"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


.



Relevant Pages

  • Re: Complex Specified Information - Pitman Formula
    ... Therefore a significant match between a reference and a test ... string is good evidence of non-random production. ... and there are no finite algorithms to compute their digits. ... probabilities of the different symbols the information source can produce. ...
    (talk.origins)
  • Re: String Reference Type
    ... All unary and binary operators have predefined implementations that are ... Therefore its always allocated in the heap and a variable of string ... As with all classes in this case y and x both reference the same String ... language depandant matter as below. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Abstract class variables question
    ... But as I think you've seen elsewhere in this thread, a value type can exist inside a class and in that case the value type is stored in the heap with the rest of the class instance. ... But as far as the "faster" goes, yes...to some extent value types have less overhead than reference types, and so can perform better in certain cases. ... Well, that would be true for a string object too, if there was any way to actually change a string. ... Seriously though, it is practically always the case that when you are writing an assignment to a reference, you're replacing the reference held by the variable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Measurement of pitch
    ... as the method used by the Pythagoreans. ... of these reference units in the quantity to be measured. ... vibrating string seems as good as anything. ... The string or pendulum in question could no doubt be specified exactly, ...
    (sci.physics)
  • Re: Abstract class variables question
    ... I think I understand boxing a little better now. ... the object that is on the heap. ... value types are copied to the heap and made into an object and reference ... String types are already reference types and all we are doing when we do ...
    (microsoft.public.dotnet.languages.csharp)