Results 1 to 7 of 7
  1. #1
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265

    When to use " ! " or a " . " when referencing objects and properties

    Here are some examples from the Microsoft website for the Access 2013 Object Model where they are giving examples of explicit and implicit references to a Controls collection on a form, and a form containing a subform.

    Code:
    Forms!OrderForm!NewData
    Forms!OrderForm.Controls!NewData
    
    
    Forms!OrderForm.ctlSubForm.Form!Controls.NewData
    Forms!OrderForm.ctlSubForm!NewData

    How do you know when to use an exclamation mark or a period as a separator between collections, objects and properties?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    One piece of information that may help is that "intelligence" only works when you use the dot ".".

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Don't you mean "intellisense"?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Yep! My bad.

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yep! My bad.
    You can just blame it on Spell Check!

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Small wonder you are confused. IMO, these two examples from Microsoft are wrong:

    Forms!OrderForm.ctlSubForm.Form!Controls.NewData
    Forms!OrderForm.ctlSubForm!NewData

    They should read:

    Forms!OrderForm!ctlSubForm.Form.Controls!NewData
    Forms!OrderForm!ctlSubForm!NewData

    The standard I try to use is : Use "!" when referring to a single member of a collection, e.g. an open form, a control, or a member of a recordset.

    Use "." when referring to a collection itself (e.g. .controls) or to a property or method.

    Very often Access can figure out what is required from the context, but I know (from experience) that there are times when using the "." results in the "property not available" (or something like that) error, and the compiler won't always catch it - it happens at runtime.

    JoeM - sometimes I think that intelligence doesn't work whether you use dot or Bang (!), especially with end-users!

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    JoeM - sometimes I think that intelligence doesn't work whether you use dot or Bang (!), especially with end-users!
    Yes, its almost as common as "common sense"!

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

Similar Threads

  1. Replies: 1
    Last Post: 09-03-2014, 03:27 AM
  2. Replies: 8
    Last Post: 07-15-2014, 05:56 PM
  3. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  4. Replies: 16
    Last Post: 07-22-2011, 09:23 AM
  5. Relocating objects via "Left" properties value
    By Ripcut in forum Programming
    Replies: 0
    Last Post: 08-01-2008, 06:40 PM

Tags for this Thread

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