Results 1 to 4 of 4
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    VBA To Use Fields With Names

    I do not have any fields with names in them, but I was reading and saw this and was curious which one is proper protocol? Do both of these mean the same thing?



    Let's say we have a field whose name is Field One - what is the proper way to reference this field using VBA
    Code:
    Me![Foo ID]
    Me.Food_ID
    Both of these work, but to me it is just as annoying as adding an underscore as it is having to add square brackets. Obviously the moral of the story DO NOT use field names with spaces, but what would be the proper way to code if it is done?

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    "Bang vs. Dot"
    http://www.utteraccess.com/forum/Per...t-t103870.html

    If you are forced to use field names that have spaces in them, then [ ] around the field name would be required in both queries and within VBA code.

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by jwhite View Post
    "Bang vs. Dot"
    http://www.utteraccess.com/forum/Per...t-t103870.html

    If you are forced to use field names that have spaces in them, then [ ] around the field name would be required in both queries and within VBA code.
    Thanks for the response. I do not use spaces in field names, but saw that both were an option to account for spaces. I was curious which was the "right" way to do do this.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Use the dot operator as an Access Operator to access an object's members. Use the Bang to reference only the default member.
    http://bytecomb.com/the-bang-exclama...erator-in-vba/

    Behind a form, use the following to access a control named My Control ...
    Me.My_Control.Value
    Me.[My Control].Value

    Behind a bound form, use the following to access a field within a column named MyField ...
    Me!MyField
    Me![MyField]

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

Similar Threads

  1. Replies: 4
    Last Post: 07-18-2016, 12:59 PM
  2. Fields Names Too Long
    By YuriGagarin in forum Database Design
    Replies: 9
    Last Post: 11-13-2015, 03:50 PM
  3. Replies: 2
    Last Post: 05-13-2015, 03:20 PM
  4. Replies: 13
    Last Post: 08-18-2014, 02:07 PM
  5. Replies: 5
    Last Post: 04-24-2011, 03:14 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