Solved

Identify what the parent of a subform is

Posted on 2011-09-14
5
264 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

707 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

12 Experts available now in Live!

Get 1:1 Help Now