I have a form that is a part of another form (subform), but sometimes I open it as a standalone form. I need to make some changes in the form when it is opened not as a subform. I tried to find a simple Boolean function that indicates whether a form is opened as a subform, and eventually I wrote the following universal function:
I use it this way:
Perhaps, it will help other developers. If you know a simpler solution, let me know.
Code:
Private Function IsSubform() As Boolean
Dim bHasParent As Boolean
On Error GoTo NotASubform
' If opened not as a subform, accessing
' the Parent property raises an error:
bHasParent = Not (Me.Parent Is Nothing)
IsSubform = True
Exit Function
NotASubform:
IsSubform = False
End Function
I use it this way:
Code:
Private Sub Form_Load()
Me.NavigationButtons = Not IsSubform()
End Sub
Perhaps, it will help other developers. If you know a simpler solution, let me know.