Share via

Using the same data entry subform on two or more parent forms

Anonymous
2023-04-12T04:17:17+00:00

I am using the same exact data entry subform on 2 forms. I'd like to have one piece of code for each usage of this particular data entry subform, but I have failed. I've used: If Me.Parent = f_to_do_det_e Then AND Ive tried If Me..Parent.Name = f_to_do_det_e

Nothing I've tried works. One of the parent forms is f_to_do_det_e and the other is f_to_do_itm_det_e_pop

Private Sub cbo_to_do_ctg_m_ctg__AfterUpdate()

On Error GoTo Err_cbo_to_do_ctg_m_ctg__AfterUpdate

If Me.Parent.Name = f_to_do_det_e Then

If Me.Dirty = True Then Me.Dirty = False 

    [Forms]![f\_to\_do\_det\_e]![fsb\_to\_do\_ctg\_lst\_ve].Requery 

    DoCmd.GoToRecord , , acNewRec 

End If 

Else

If Me.Dirty = True Then Me.Dirty = False 

[Forms]![f\_to\_do\_itm\_det\_e\_pop]![fsb\_to\_do\_ctg\_lst\_ve].Requery 

DoCmd.GoToRecord , , acNewRec 

End If 

End If

Exit_cbo_to_do_ctg_m_ctg__AfterUpdate:

Exit Sub 

Err_cbo_to_do_ctg_m_ctg__AfterUpdate:

MsgBox Err.Description 

Resume Exit\_cbo\_to\_do\_ctg\_m\_ctg\_\_AfterUpdate 

End Sub

Microsoft 365 and Office | Access | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2023-04-12T20:12:19+00:00

Maybe:

If Me.Parent.Name = "f_to_do_det_e" Then

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
2023-04-12T04:32:55+00:00

> If Me.Parent = f_to_do_det_e

The Parent property, per the help file, returns the parent OBJECT for the specified object.
Yes, it's a shame that the item to be defined is used to define it. Out of my control :-)

But this means that the subform's Parent OBJECT is being returned.

f_to_do_det_e is not a (form) object. It is the name of such object.

If you try to Debug > Compile this code, you will get an error.

> If Me..Parent.Name = f_to_do_det_e

The Name property, per the help file, returns the string expression that identifies the name of an object.

Yes, it's a shame that the item to be defined is used to define it. Out of my control :-)

f_to_do_det_e is not a string.

If you try to Debug > Compile this code, you will get an error.

Armed with this understanding, it appears you can correctly write your code by comparing two objects, or two strings.

Unfortunately when you try, you will find that comparing two objects is not possible.

If Me.Parent = Forms!f_to_do_det_e > Type Mismatch.

But you CAN compare two strings:

If Me.Parent.Name = "f_to_do_det_e" then MsgBox "Eureka!"

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-04-12T18:17:18+00:00

    I am using the same exact data entry subform on 2 forms. I'd like to have one piece of code for each usage of this particular data entry subform,

    Hi VWP1,

    You could try something like this:

    Private Sub cbo_to_do_ctg_m_ctg__AfterUpdate()

    If (Me.Dirty) Then Me.Dirty = False
    
    Me.Parent![fsb\_to\_do\_ctg\_lst\_ve].Requery
    
    DoCmd.GoToRecord , , acNewRec
    

    End Sub

    In the above example, I assume Me represents the subform.

    And DoCmd.GoToRecord, is that command for the Parent-form?

    Imb.

    Was this answer helpful?

    0 comments No comments
  2. ScottGem 68,830 Reputation points Volunteer Moderator
    2023-04-12T11:30:23+00:00

    I'm not clear on what the problem is here, (besides incorrect code). When you embed a subform using the subform wizard, you are asked if you want to select an existing form. Doing so and selecting the same form on both mainforms will place the same subform on both mainforms. I don't see any need for code. here.

    Now if you want to use different subfoms on the same mainform, then you would use code to adjust the subforms Source property with the name of the subform.

    Was this answer helpful?

    0 comments No comments