Re: How to tell if a form is open?




"deko" <deko@xxxxxxxxxx> schreef in bericht news:xpadnY5QCqMTq5feRVn-1g@xxxxxxxxxxxxxx
> In my adventures with VBA I've come across two different methods to
> determine if a form is open.
>
> I'm wondering if someone more experienced than I am can help me decide which
> one is better - does it matter? FrmIsOpen does not need to set any
> objects - is that enough to qualify as the better option?
>
> Public Function FrmIsOpen(frm As String) As Boolean
> If SysCmd(acSysCmdGetObjectState, acForm, frm) <> 0 Then FrmIsOpen =
> True
> End Function
>
> Public Function FrmIsLoaded(frm As String) As Boolean
> Dim prj As Object
> Set prj = Application.CurrentProject
> FrmIsLoaded = prj.AllForms(frm).IsLoaded
> Set prj = Nothing
> End Function
>

Hi Deko,
Here is another one to choose from ...

Public Function IsLoaded (frm as string) as Boolean
Dim i as integer
For i = 0 To Forms.Count - 1
If Forms(i).FormName = frm Then
IsLoaded = True
Exit Function
End If
Next
End Function

I would not bother too much about which one is better.
Maybe if you call the function 100+ times it matters???

Arno R
.



Relevant Pages

  • Re: Incorporating optional function argument
    ... If, for instance, you had MsgBox =Test or Debug.Print Test there would be something for the user to observe. ... Public Function test(strMsg As String, Optional blnVal As Boolean = False) ... A break point at the Public Function line does not result in the code breaking. ...
    (microsoft.public.access.formscoding)
  • Re: Incorporating optional function argument
    ... Public Function test(strMsg As String, Optional blnVal As Boolean = False) ... If I put this into the event property, ...
    (microsoft.public.access.formscoding)
  • Re: Command button to open form and find record
    ... Opens the form if it is not already open. ... Public Function OpenFormTo(strForm As String, strWhere As String, Optional bGotoNewRecord As Boolean, _ ... Optional strOpenArgs As String) As Boolean ... Public Function HasProperty ...
    (microsoft.public.access.forms)
  • Re: Incorporating optional function argument
    ... For now I have added the optional argument to the event property function calls. ... Public Function test(strMsg As String, Optional blnVal As Boolean = False) ...
    (microsoft.public.access.formscoding)
  • How to tell if a form is open?
    ... Public Function FrmIsLoaded(frm As String) As Boolean ... Set prj = Application.CurrentProject ...
    (comp.databases.ms-access)

Loading