IsLoaded

  • Thread starter Thread starter paul
  • Start date Start date
P

paul

I have the following code to determine if a form is loaded. I would like to
use it to find out if a "SUBFORM" is loaded. I tried it and it will not
work. Please would someone advice me how to edit this code to work with the
subform. Thanks.

Function IsLoaded(ByVal strFormName As String) As Integer
' 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
 
paul said:
I have the following code to determine if a form is loaded. I would
like to use it to find out if a "SUBFORM" is loaded. I tried it and
it will not work. Please would someone advice me how to edit this
code to work with the subform. Thanks.

Function IsLoaded(ByVal strFormName As String) As Integer
' 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

This code cannot be adapted to tell if a subform is loaded, because a
subform is not "loaded" in the same way that a form is loaded.
Similarly, a subform is not a member of the Forms collection (which
contains all open forms), so you can't search for it there.
Furthermore, there could be multiple instances of the same form object
appearing in several different subform controls at the same time.

It would be possible to search every open form for any subform controls,
and then check each subform control's SourceObject to see if it is the
name of the subform you're looking for, and if those subforms have
subform controls search each of *them*, and so on. But is it worth it
for what you want to do? Could you explain in broader terms what you're
trying to accomplish?
 
Back
Top