Results 1 to 9 of 9
  1. #1
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Syntax for reference to parent form control

    Dear loungers,

    I must be doing something dumb here. I have a form with a subform, on the subform I have an "on double-click" macro that needs to set a value in the parent form. I have tried various syntax to refer to this control and keep getting a 32004 error which indicates the field doesn't exist.

    I have tried both of these:
    me.parent!controlname
    forms!formname!controlname
    Even though I think this is VBA only I even tried:
    forms(formname).controlname

    What am I doing wrong?

    While on thsi general subject does anyone know of a good syntax description - I'd like to know, for example, what a dot means as opposed to an exclaimation mark. And mostly my controls have the same name as the data item they are sourced from, however I have never been sure if this is a good idea, any recommendations of comments on drawbacks of this habit?

    Thank you.......................... liz

  2. #2
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    On the issue of parent and subform controls, this page pretty much covers it: http://access.mvps.org/access/forms/frm0031.htm

    O
    n exclamation vs. dot, that's a Visual Basic thing. Exclamation marks are used for collection access, dots are for methods and properties.

    Personally, on forms that I create, I use a syntax that uses prefixes to allow me to know the type of control, just from looking at the name: txt for Text boxes, btn for buttons, cb for comboboxes, lst for lists and so on. I don't really like using controls with the same names as the data fields, although context will make it clear.

  3. The Following User Says Thank You to ruirib For This Useful Post:

    lizat (2012-08-10)

  4. #3
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Here is a good explanation of dot vs. exclamation point: http://books.google.pt/books?id=0vaE...access&f=false

  5. The Following User Says Thank You to ruirib For This Useful Post:

    lizat (2012-08-10)

  6. #4
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Ok, I found that I already had a copy of the useful document on the MVPS site and it is what I have used for years as a reference when in doubt. So it looks to me as if everything is named correctly.

    On the sub-form the On-Doubleclick macro uses this to refer to a field on the main form: Me.Parent![GoToProcId].
    On running the macro I get the error "The control name 'Me.Parent![GoToProcId]' is misspelled or refers to a control that doesn't exist".
    I have checked the main form the control does exist and is called: [GoToProcId].

    The only other relevant information I can think of is that the [GoToProcId] control is in the footer of the main form, the sub-form is on a tab control, would that make any difference?

    Stumped! Any ideas? Thank you........................ liz

  7. #5
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Weird, I can't see anything wrong in what you are doing. Even went to one of my apps with subforms in tabs and I use that same notation. Have you tried the Forms!Mainform!ControlName notation?

  8. #6
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    I don't believe you can use the Me.xxx syntax in macros, only in VBA. Try the Forms! construct as Rui suggests and see if that works for you.
    Wendell

  9. #7
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Hmmm I did miss the macro part, as I just use code whenever I can. Thanks for that, Wendell .

  10. #8
    New Lounger
    Join Date
    Oct 2010
    Location
    Canberra ACT Australia
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Re control naming, I've experienced some situations where controls with same name as data have caused ambiguity error, eg (from memory) calculations in reports using the value in a control. I use prefixes as per ruirib.

  11. #9
    New Lounger
    Join Date
    Dec 2009
    Location
    Maryland USA
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Could it be...?

    Hi All

    I ran into something like this recently, and Access VBA was very cranky about my choice of command options. It turned out that the object that I was describing inadvertently contained a reserved word. I don't remember what word it was, but it was kind of 'buried' in the field name.

    Could the issue be that there's a 'goto' buried in this object name?

    Don

Posting Permissions

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