Parent Form

  • Thread starter Thread starter Mary Fetsch
  • Start date Start date
M

Mary Fetsch

In Access 2000, I have a utility module that's used for forms with a parent
form and for forms without a parent form. What's the easiest way to check
if a form has a parent form?
 
Mary Fetsch said:
In Access 2000, I have a utility module that's used for forms with a
parent form and for forms without a parent form. What's the easiest
way to check if a form has a parent form?

The only way I know is to try to access Form.Parent and see if an error
(2452) is raised, or try to set a reference to the parent (ignoring
errors) and see if you succeed; e.g.:

Sub DoSomething(pForm As Form)

Dim frmParent As Form

On Error Resume Next
Set frmParent = pForm.Parent
On Error GoTo YourNormalErrorHandler

If frmParent Is Nothing Then
' pForm is the top-level form.
Else
' pForm is a subform.
End If

End Sub
 
Mary said:
In Access 2000, I have a utility module that's used for forms with a parent
form and for forms without a parent form. What's the easiest way to check
if a form has a parent form?


A form displayed as a subform has a Parent property, but a
main form does not.

On Error Resume Next
strjunk = Me.Parent.Name
Select Case Err.Number
Case 0
'Me is a subform
Case 2452
'Me is a main form
Case Else
'a real error happened
End Select
On Error GoTo yourerrorhandler
 
Thanks!

Marshall Barton said:
A form displayed as a subform has a Parent property, but a
main form does not.

On Error Resume Next
strjunk = Me.Parent.Name
Select Case Err.Number
Case 0
'Me is a subform
Case 2452
'Me is a main form
Case Else
'a real error happened
End Select
On Error GoTo yourerrorhandler
 
Thanks!

Dirk Goldgar said:
The only way I know is to try to access Form.Parent and see if an error
(2452) is raised, or try to set a reference to the parent (ignoring
errors) and see if you succeed; e.g.:

Sub DoSomething(pForm As Form)

Dim frmParent As Form

On Error Resume Next
Set frmParent = pForm.Parent
On Error GoTo YourNormalErrorHandler

If frmParent Is Nothing Then
' pForm is the top-level form.
Else
' pForm is a subform.
End If

End Sub

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top