Results 1 to 5 of 5
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Subform Tricks

    I believe that there is a command in MS Access 2013 that allows one to determine from a subform who its parent is. Since, I have inherited this project, I have a lot of subforms and
    I would just like to know if that command is available in MS Access 2010?

    If it is then what is it and how do I use it?

    Any help appreciated. Thanks in advance.



    Respectfully,

    Lou Reed

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    it's not a command.

    in the subform form in vba to return the name of the parent form you use.

    me.parent.name

    where to use it is up to you, depends on why and when you want to know it

    e.g. in the form open event you might put

    me.txtParentname=me.parent.name

    where me.txtParentname is the name of a textbox control on your form.

    it's been available since subforms were invented

    NOTE: if you run this code when you have opened the subform as a form in its own right, you will get an error because there is no parent.

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I understand your point, but my point is should I do something different because my db may have subforms?

    I have not created a great part of this db so, it is possible that in some form (which I did not create) using this option would affect that when it open , etc.

    Any help appreciated. Thanks in advance.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    my point is should I do something different because my db may have subforms
    no reason I can think of

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    There's probably more elegant examples than what I just came up with, but how about
    Code:
    Public Sub WhoYerDaddy()
    
    Dim ctl As Control
    Dim strName As String, strPrint As String
    Dim obj As AccessObject
    
    On Error GoTo errHandler
    
    For Each obj In Application.CurrentProject.AllForms
      strName = obj.Name
      DoCmd.OpenForm strName, acDesign 'open in design view to enumerate controls & prevent running code
        For Each ctl In Forms(strName).Controls
        'if type is subform control, build print statement with attributes
          If ctl.ControlType = acSubform Then
             strPrint = "Form Name: " & strName & "; Subform Control Name: " & ctl.Name
             strPrint = strPrint & "; Source Object: " & ctl.Form.Name
             Debug.Print strPrint
          End If
    SkipPrint:
       Next
      DoCmd.Close acForm, strName
    Next
    
    Exit Sub
    
    errHandler:
    If Err.Number = 2467 Then 'trying to get an attribute that doesn't exist (source object)
       Debug.Print "Subform control [" & ctl.Name & "] on form [" & strName & "] appears to have no source object."
       Resume SkipPrint
    Else
       MsgBox Err.Number & ": " & Err.Description
    End If
    
    End Sub
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-05-2016, 02:23 PM
  2. Replies: 1
    Last Post: 02-25-2016, 01:39 PM
  3. Replies: 7
    Last Post: 04-15-2014, 01:15 PM
  4. Replies: 6
    Last Post: 05-05-2012, 08:43 AM
  5. Replies: 4
    Last Post: 03-30-2012, 01:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums