Check if Form is Visible ?

D

Dave Ruhl

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
 
B

Bruce M. Thompson

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
 
D

Dave Ruhl

Thanks! That's just what I was looking for!
-----Original Message-----

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top