Solved

Identify what the parent of a subform is

Posted on 2011-09-14
5
265 Views
Last Modified: 2012-06-22
I have two forms that both use a comments subform.  However, depending on which group opens the form is which textbox for the Claim id to be drawn from.  I tried the Me.Parent, but that did not work to identify which form the subform was being used on.
Private Sub CmdNew_Click()
On Error GoTo Err_CmdNew_Click

    DoCmd.OpenForm "FrmNotesView"
    DoCmd.GoToRecord , , acNewRec

If Me.Parent = Forms!frmACHClaims Then
    Forms.FrmNotesView.TxtClaimID = Forms!frmACHClaims!TxtClaimID
    Forms.FrmNotesView.ComClaimID = Forms!frmACHClaims!TxtClaimID
ElseIf Me.Parent = Forms!FrmClaims Then
    Forms.FrmNotesView.TxtClaimID = Forms!FrmClaims!TxtClaimID
    Forms.FrmNotesView.ComClaimID = Forms!FrmClaims!TxtClaimID
End If

Exit_CmdNew_Click:
    Exit Sub
Err_CmdNew_Click:
        MsgBox "Error Number: " & Err.Number & _
           "Description: " & Err.Description & _
           "Procedure: CmdNew_Click", vbOKOnly, "Error Message"
    Resume Exit_CmdNew_Click
    
End Sub

Open in new window

0
Comment
Question by:ssmith94015
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 36539858
Me.Parent.Name will give you the actual name of the form that the subform resides on.
0
 
LVL 33

Expert Comment

by:Norie
ID: 36539860
Me.Parent should work, where/how  did you try it?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 36539862
ie:

If Me.Parent.Name = "frmACHClaims" Then
0
 
LVL 84
ID: 36541990
<no points please>

The other Experts have provided you with the fix, but your code isn't working because you're comparing the value of Me.Parent (which returns a string value containing the name of the Parent form, if there is one), with the value of Forms!frmACHClaims, which would return a Form object. You could fix it as described by mbizup, or you could do this:

Me.Parent = Forms!frmACHClaims.Name

This would return the Name of that form (which would be "frmACHClaims"), instead of the Form object.
0
 

Author Closing Comment

by:ssmith94015
ID: 36543391
And thanks to LMConsulting for the explanation.  This does precisely what I want.

Sandra
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
This collection of functions covers all the normal rounding methods of just about any numeric value.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now