Subform References

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaad
    New Member
    • Oct 2009
    • 158

    Subform References

    I'm curious about the difference of these two as I had to come here and ask how to reference a subform from an OnClose event of a popup.
    Code:
    Forms![FormName]![SubFormName]![ControlName]
    Forms("FormName")![SubFormName]![ControlName]
    why is one with quotation marks and no Bang? (that's the one that worked with my popup by the way)

    ** EDIT **
    This question was posted within the article Referring to Items on a Sub-Form, and referes to that article.
    Last edited by NeoPa; Feb 13 '11, 08:55 PM. Reason: Please don't ask questions in the Insights section or in other people's threads.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    Objects generally, and collections specifically, have various different ways of being referenced, some of which are defaults, and some which are ways of referring to individual items. VBA has has various shortcuts available, so that referring to things is not always so long-winded. The Bang (!), is often used to denote a shortcut, as it is in this case.

    In this case, items from a collection (Forms) can be referred to as Collection(Item_Identifier). Item_Identifier can either be specified as a numerical value, where it refers to the nth element in the collection, or as a string value, where it refers to the Name of the item required. The second line you show is an example of the latter form. The first is a shortcut, or alternative version, of that. There is a difference in that the first line can only work with the name specified in the code itself, whereas the second can use a parameter that is a variable, thus the value used is entirely unknown to the developer.

    I hope this answers your question.

    Comment

    • jaad
      New Member
      • Oct 2009
      • 158

      #3
      it has, thank you for taking the time to explain it to me. You see, this is the sort of information that I find valuable. I can grow with this and start creating instead of copying and pasting a quick fix for a code; I know what it is, and how to use it- and why. Examples are great for a quick way of getting the job done but as a musician who plays music by ear, you can't compare this musician with one that has learned about the structure of music. anyone can play music, but few can truly compose a great piece. thanks again Neopa

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32662

        #4
        Very pleasing to hear that Jaad :-)

        Comment

        Working...