How to check if a form has a parent form (1 Viewer)

jeremia.morling

New member
Local time
Today, 12:40
Joined
Sep 26, 2008
Messages
2
Hi!
I have a form which I sometimes use standalone, and sometimes as a subform. When used as a subform I would like to load data from the main form when creating new records in the subform.

I thought that I could write something like this in the subform sub "Form_BeforeInsert":
If (Me.Parent <> Null) Then
...
End If

However, if I try to run this code I get runtime error 2452, which says something about illegal reference to the property Parent.

I have tried to search the web for how to write a test for if a parent form exists, but I have not found anything.:confused:

Any help would be appreciated!
/ Jeremia
 

MarkK

bit cruncher
Local time
Today, 03:40
Joined
Mar 17, 2004
Messages
8,186
I do this...
Code:
Private Property Get HasParent as boolean
On error goto handler
  HasParent = Typename(Me.Parent.Name) = "String"
  Exit Property
handler:
End Property
If a parent form exists, the data type of its name property will be a string and the property returns 'True.' Otherwise an error occurs and the property returns 'False.'

And welcome to the forum.
 

jeremia.morling

New member
Local time
Today, 12:40
Joined
Sep 26, 2008
Messages
2
Thanks a lot for the answer!
I was thinking about something like that, but I could not figure out how exception handling was done in VBA and I thought that there must be some more sofisticated way of doing it. ;)
 

Users who are viewing this thread

Top Bottom