469,314 Members | 2,238 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

How to reference parent form from subform when parent name can be different

374 256MB
All,

I want to reference a button on the parent form of a subform. The parent however could be two different form names.

frmlog

frmcorrective

How do I check which form is loaded in order to create the reference to the correct parent? The parent will always be loaded at the time the subform is being used.

I think the correct syntax for referencing a parent is along the lines of:

Forms!frmlog!tglchange.enabled = true

Thanks for any help,

Chris
Sep 14 '10 #1

✓ answered by munkee

Couldnt get sourceobject working correctly but I managed with this:

Expand|Select|Wrap|Line Numbers
  1. If Me.Parent.Name = "frmlog" Then
  2.     MsgBox "frmlog"
  3. ElseIf Me.Parent.Name = "Frmcorrective" Then
  4.     MsgBox "frmcorrective"
  5. End If

5 26042
TheSmileyCoder
2,321 Expert Mod 2GB
I think something like this would work for you:

Expand|Select|Wrap|Line Numbers
  1. If me.Parent.SourceObject="frmLog" Then
  2.    me.Parent.form.tglChange.Enabled=True
  3. elseif me.parent.sourceobject="frmCorrective" then
  4.   'blah blah
  5. end IF
Sep 14 '10 #2
munkee
374 256MB
damnit! thats was so obvious why did I not even think.. thanks!


Hmm for some reason it keeps only referencing frmlog when I load the code whilst using frmcorrective.
Sep 14 '10 #3
TheSmileyCoder
2,321 Expert Mod 2GB
I believe, that subforms are loaded before main forms.
I remember messing around with this at some point, and in the end i put alot of msgbox "frm_Thisform opening", msgbox "frm_thisForm Loading" to try to determine the order of loading. I'd suggest trying that.
Sep 14 '10 #4
munkee
374 256MB
Couldnt get sourceobject working correctly but I managed with this:

Expand|Select|Wrap|Line Numbers
  1. If Me.Parent.Name = "frmlog" Then
  2.     MsgBox "frmlog"
  3. ElseIf Me.Parent.Name = "Frmcorrective" Then
  4.     MsgBox "frmcorrective"
  5. End If
Sep 14 '10 #5
TheSmileyCoder
2,321 Expert Mod 2GB
Yes of course. I'm used to using it a bit the other way around, where im in the parent, and want to know which subform is currently displayed. The sourceobject is only used for a control containing a form.

I believe you can choose your own reply as "best answer", so the thread gets marked as answered.
Sep 14 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by =?Utf-8?B?aWxy?= | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.