locked
me.field me![field] me!field RRS feed

  • General discussion

  • whet is the difference between me. and me!

    or which one should be used ?

    Wednesday, June 1, 2016 8:26 AM

All replies

  • The general rule is "!" before objects and "." before properties and methods.

    So -

    Me!txtBoxName  'Control Name
    
    Me!FieldName     ' Refers to underlying field
    
    
    
    
    Me!txtBoxName.Enabled ' Property of control
    
    Me.Requery    ' Method
    

    That said, in VBA you CAN use . when you are referring to controls, and intellisense facilitates this with autocompletion...

    Me.txtboxName  ' also acceptable in referring to controls

    A couple additional notes...

    If you want to refer to the field behind a control not the control itself, you must use !

    Also, when referring to controls in a query, you must use ! and you must use the form name rather than "me"  (me and "." only work for control references in VBA, not SQL)


    Miriam Bizup Access MVP

    Wednesday, June 1, 2016 8:54 AM
  • The title of your question also appears to be asking about the usage of square brackets...

    The square brackets make it clear to Access that something is a field or control name.  They are *necessary* if you have spaces, some special characters or reserved words in your names, such as:

    [My Textbox]  'Brackets needed because of the space
    
    [Date]  'Brackets needed to differentiate a field or control named Date from the VBA function Date()
    

    However, if you follow good naming conventions and avoid using spaces special characters and reserved words in your names (eg: use MyTextbox and InvoiceDate instead of the above names), the brackets are not needed.


    Miriam Bizup Access MVP



    • Edited by mbizup MVP Wednesday, June 1, 2016 9:19 AM
    Wednesday, June 1, 2016 9:18 AM
  • whet is the difference between me. and me!

    or which one should be used ?

    Hi tekoko,

    In addition of the answers that Miriam gave, you can also address fields or controls with the syntax:

        Me("MyControl"),

    or more general using a variable:

        Me(MyVariable).

    The latter is very powerful in structuring code through generalization.

    Imb.

    Wednesday, June 1, 2016 9:30 AM