MajP
You've got your good things, and you've got mine.
- Local time
- Today, 01:05
- Joined
- May 21, 2018
- Messages
- 9,973
Not sure what you really mean. I interpret that to simply mean you want code to determine if a form is loaded as a subform not if it is loaded both as a main form and also as a subform.a (short) function that checkes if a form isloaded as a form and also if it's loaded as a subform.
Isladogs showed how to show if a form is loaded as a main form.
Code:
Function IsFormLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
On Error GoTo Err_Handler
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
If Forms(strFormName).CurrentView <> 0 Then
IsFormLoaded = True
End If
End If
Exit_Handler:
Exit Function
Err_Handler:
MsgBox "Error " & err & " in IsFormLoaded procedure : " & Err.Description
Resume Exit_Handler
End Function
To see if a form is loaded as a subform
Code:
Public Function IsSubFormLoaded(ByVal strFormName As String) As Boolean
Dim sFrm As Access.Form
Dim ctrl As Access.Control
For Each sFrm In Forms
For Each ctrl In sFrm.Controls
If ctrl.ControlType = acSubform Then
If ctrl.Form.Name = strFormName Then
IsSubFormLoaded = True
Exit Function
End If
End If
Next ctrl
Next sFrm
End Function
If you really want to know if it is loaded as either a main form or a subform, then wrap those functions
Code:
Public Function isFormOrSubFormLoaded(ByVal strFormName As String) As Boolean
If IsFormLoaded(strFormName) Or IsSubFormLoaded(strFormName) Then isFormOrSubFormLoaded = True
End Function