Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049

    Question Unanswered: Referencing Subform's Form Properties

    Just a quick one that has me drawing blanks atm.

    How do I make a reference to a subform's form properties like AllowEdits? Without direct references.

    IE

    If Eval(strParentFormName & "!" & strSubformName & ".AllowEdits") = True Then....

    That kind of thing. I tried for an hour last night to get that to work but I never cracked it. I probably will in time, but hey, no harm in asking!

    Cheers

    ST
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I've had the same moments myself. I've used:

    If Forms!MainFormName!SubFormName.AllowEdits = True then....
    (or Forms!MainFormName.Form!SubFormName.AllowEdits but I'm not 100% sure on this syntax.)

    I've also used this in some code I had (for a popup calendar form) to write the date selected on the calendar popup form to either a main form or sub form and used this code (which is unrelated to your question but I like the way it does the referencing to the subform):

    If IsNull(Me!SubFormName) Or Me!SubFormName = "" Then
    Forms(Me!FormName)(Me!FieldName) = Me!WorkDate
    Else
    Forms(Me!FormName).Controls(Me!SubFormName).Form.C ontrols(Me!FieldName) = Me!WorkDate
    End If

    Hope that helps.
    Last edited by pkstormy; 01-15-08 at 22:22.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    This may help as well. I came across this guy's site while poking through MSDN forums on Access coding:

    http://www.rogersaccesslibrary.com/d...mReference.mdb

    I did not download the file, but the description seems pretty good.


    Have fun,
    tc

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    Forms(formName).Controls(subFormName)
    EDIT: Scratch the above, I don't think you can access the properties using this notation.
    George
    Home | Blog

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ignore my last post
    Code:
    For i = 0 To Forms(formName).Controls(subFormName).Properties.Count - 1
        Debug.Print i & ") " & Forms(formName).Controls(subFormName).Properties(i).Name
    Next i
    George
    Home | Blog

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Hmm... Yes, I tried all of those... except that last one George

    But I am referring to the objects from a public function, so I can't use the "Me" object. I also had a look at that database from roger's site, but it isn't using strings and the code is all directly referring to object names and I am trying to derive them.

    I've been trying to build the reference to the objects from strings, for example: Eval("Forms!MainformName.Form![SubformName].AllowEdits")

    I'm using things like Screen.ActiveForm to get the name of the mainform. When I try these methods I get RTE 2766: The object doesn't contain the automation object "AllowEdits".

    I get around it by passing the AllowEdits property value (Me.AllowEdits) to the called public function, but I'd rather the public function not need that argument passed... or any arguments for that matter.

    ------------------
    Edit 1: I found that this:

    Code:
    Eval("Forms!MainformName.Form![SubformName].Form.AllowEdits")
    Does the trick, but to do that, I would still have to pass along the name of the subform object to the function, and I would prefer not to.

    What I need now is a way to access the currently active subform... even just it's name since I can get the name of the mainform with Screen.ActiveForm. The focus is inside a subform at the time.

    So I'm close, all I need now is a code segment that returns the name of the currently active subform.

    Not such a quick question as I thought

    ------------------------
    Edit 2: Never mind. Got it. Told ya I'd get it in time!

    Code:
    Eval("Forms!" & Screen.ActiveForm.Name & ".Form![" & Screen.ActiveForm.ActiveControl.Name & "].Form.AllowEdits")
    Thanks for the guidance anyway

    Hope this helps someone else too!
    Last edited by StarTrekker; 01-16-08 at 09:09.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    well done!

    I'd avoid the eval() function if I were you though...
    Use the collection named index syntax I noted in previous posts; it's far superior in terms of performance (not to mention debugging!).
    George
    Home | Blog

  8. #8
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I'd still need to derive the name of the current subform object. Is there a neater way to get it than I have done?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  9. #9
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I can't think of a more elegant solution to getting the subform name... I assumed you were passing it as a parameter in your function...

    You can still use what you've done with the named index collection notation if needed.
    George
    Home | Blog

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    possibly helpful item from stock - recursion in a module to find the active control (not form) in any degree (including none) of subform nesting:

    Code:
    Public Function GetTarget(Optional ctlParent As Variant) As Control
        Dim ActControl As Control
        If IsMissing(ctlParent) Then
            Set ActControl = Screen.ActiveForm.ActiveControl
        Else
            Set ActControl = ctlParent.Form.ActiveControl
        End If
        If ActControl.ControlType = acSubform Then
            Set GetTarget = GetTarget(ActControl)
        Else
            Set GetTarget = ActControl
        End If
    End Function
    and then, anywhere:
    dim frmX as form
    set frmX = GetTarget.parent.form
    frmX.allowedits = False

    izy

    LATER: forgot to acknowledge the original recursion scheme from forum member "bachatero"
    Last edited by izyrider; 01-16-08 at 14:34. Reason: forgot acknowledgement
    currently using SS 2008R2

  11. #11
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Thanks izyrider

    I'm not yet convinced that this solution is more or less elegant. Yes, it dodges the Eval function, but my God it's a whole lot more coding so I'm not sure what advantages (if any) this would give over what I am currently doing.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  12. #12
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i have my generic functions (inclucing GetTarget) in a module that i getExternal/import into each new application.

    from there, the only manual coding is one Dim and one Set (plus whatever you plan to do to the form of course).
    ...not a whole lot of code IMHO to get the activeform or the activecontrol object from any arbitrary form/sub/sub/sub/etc structures.

    for a single property, use an implicit object:
    gettarget.parent.form.allowedits = False
    ...does it get any simpler than that?
    (for multiple properties you probably save execution time by instantiating the object)

    the advantage i see is generic, zero maintenenance, reusable code.

    izy
    currently using SS 2008R2

  13. #13
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Ah, I forgot to consider sub-sub forms etc... probably because I never use them.

    Thanks again
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •