> How can I check to see if a form is visible from another
> form ? I've tried the following code, which works fine
> if the form IS visible, but I get an error if it isn't.
> I realize I could handle the error and get around it, but
> there should be a simpler way. Thanks in advance!
>
> If Forms!frmMyForm.Visible = True Then
> ' do whatever....
> Else
> ' do whatever else....
> Endif
When the error is generated, is the form open, but just invisible, or just not
open? If you want to see if the form is open, try this instead:
'***
Dim IsVisible As Boolean
If IsLoaded(strFormName) Then
IsVisible = Forms(strFormName).Visible
Else 'Form isn't open, so it's not visible, either
IsVisible = False
End If
'***
Copy and paste this function to a standard module (a global module, not a module
behind a form or report):
'***FUNCTION START
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed
Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
'***FUNCTION END
--
Bruce M. Thompson, Microsoft Access MVP
(E-Mail Removed) (See the Access FAQ at
http://www.mvps.org/access)
>> NO Email Please. Keep all communications
within the newsgroups so that all might benefit.<<