[AccessD] Bang and Dot operator in Runtimes.

JWColby jwcolby at colbyconsulting.com
Tue Aug 22 08:22:37 CDT 2006


In addition to this, you should understand the concepts.  

Starting (I believe) in Access97, Microsoft started trying to steer
developers into a consistent usage of the Dot ( . ) and Bang ( ! )
operators.  

For backwards compatibility they left the ability to use either, but the DOT
operator refers to PROPERTIES, throughout the language.  You never see (for
example) MyCombo!Value, and in fact that probably wouldn't even work.  The
PROPERTY Value is referred to using the DOT operator - MyCombo.Value.  

The BANG operator ( ! ) refers to OBJECTS, MyForm!MyTextBox (for example),
where MyForm is an object (a form object) and MyTextBox is an object (a text
box object).  So the syntactically correct usage is
MyForm!MyControl.SomeProperty, where SomeProperty is a property of the
OBJECT MyControl contained in the (default) controls collection of the
MyForm object.

Notice that the same sequence is used recordsets (for example)

	MyRecordset!MyField[.SomeProperty]

	MyRecordset is an object.
	MyField is also AN OBJECT, it is a field object in the DAO (or ADO
for that matter) programming syntax.

You would then use it in a statement:
	
	MyRecordset!MyField = "Test"

OR

	MyRecordset!MyField.Value = "Test"

You may succeed in mixing them (bang and dot) up and still get the program
to work, but it is only because VBA attempts to "guess" what you mean, and
succeeds most of the time.  It is those times when it fails that you get
seemingly unexplainable results.  It is our responsibility to use explicit
syntax to TELL VBA what we mean, avoiding the guesswork.

John W. Colby
Colby Consulting
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of A.D.TEJPAL
Sent: Tuesday, August 22, 2006 2:47 AM
To: Access Developers discussion and problem solving
Cc: ADT
Subject: Re: [AccessD] Bang and Dot operator in Runtimes.

John,

    In Access 2000 as well as 2003, tests conducted on form named F_BangDot,
having unbound text boxes named TxtDate_A to L, all the eleven alternative
statements in click event of command button CmdTest, as given below, are
found to work effectively.

    The problem reported by you should not have any reason to occur. You
might like to try it out on a newly created form. If still any problem, I
could send you a copy of this form if desired, demonstrating all the
alternatives.

    For use within code module of a form containing the text box in
question, use of Me identifier, as in statement (A) below, is considered
most efficient.

Best wishes,
A.D.Tejpal
---------------

======================================
Private Sub CmdTest_Click()
    Me.TxtDate_A = #1/1/2001#                                ' (A)
    
    
    Me("TxtDate_B") = #1/2/2001#                            ' (B)
    Me!TxtDate_C = #1/3/2001#                                ' (C)
    
    Me.Controls("TxtDate_D") = #1/4/2001#               ' (D)
    Me.Controls!TxtDate_E = #1/5/2001#                   ' (E)
    
    Forms("F_BangDot")("TxtDate_F") _
                                                = #1/6/2001#            '
(F)
    Forms!F_BangDot!TxtDate_G = #1/7/2001#         ' (G)
    
    Forms("F_BangDot").Controls("TxtDate_H") _
                                                = #1/8/2001#            '
(H)
    Forms!F_BangDot.Controls!TxtDate_J _
                                                = #1/9/2001#            '
(J)
                                                
    Forms("F_BangDot").TxtDate_K = #1/10/2001#    ' (K)
    Forms!F_BangDot.TxtDate_L = #1/11/2001#        ' (L)
    
    ' Note:
    ' (a) Statement (A) is considered the most efficient
    '       when used within code module of form
    '       containing the text box. - although all the oher
    '       statements, i.e. (B) to (L) are also found to
    '       work effectively.
    ' (b) Statement (B) is the preferred short style of
    '       complete syntax represented by statement (D).
    '       This syntax can be adopted universally by
    '       substituting Forms("FormName") instead of Me
    '       as illustrated in (F) and (H).
    ' (c) Statements (C), (E), (G) and (J) are equivalent
    '       to (B), (D), (F) and (H) respectively, but with
    '       bang operator.
    ' (d) Statements (K) & (L) are hybrid versions.
    ' (e) Basically, bang operator is meant as a replacement
    '       for ("--") style, when referring to a member in
    '       a collection.
    
    ' Important:
    '       In queries, bang operator is the only one that is
    '       accepted.
End Sub
======================================

  ----- Original Message -----
  From: John Skolits
  To: 'Access Developers discussion and problem solving' 
  Sent: Tuesday, August 22, 2006 07:39
  Subject: Re: [AccessD] Bang and Dot operator in Runtimes.


  Actually, it is a bound form, but this turns out to be an unbound text box
on the form. So, there is no field named "txtDate", just the text box name.
Therefore, why would the "!" work and not the "."

  I could certainly re-design the form, but the reason for posting the
  question in the first place is to find out why is this happening anyway.
  And I've seen it many times before. Must have something to do with it
being an unbound control. 

  John

  -----Original Message-----
  From: accessd-bounces at databaseadvisors.com
  [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Erwin Craps -
IT
  Helps
  Sent: Monday, August 21, 2006 5:44 PM
  To: Access Developers discussion and problem solving
  Subject: Re: [AccessD] Bang and Dot operator in Runtimes.

  When using me.txtdate your are refering to the control on a form.
  When using me!txtdate you are refering to the field from the forms
  recordset (rowsource). 

  But for what concerns your error.
  When using me.txtDate = #1/1/2001# the code can fails depending of whats
in the controlsource. If you replace the . By a ! Than you maybe have no
error but you are refering tho the field instead of the control (in case a
field exists with that name).

  -----Oorspronkelijk bericht-----
  Van: accessd-bounces at databaseadvisors.com
  [mailto:accessd-bounces at databaseadvisors.com] Namens John Skolits
  Verzonden: maandag 21 augustus 2006 21:46
  Aan: 'Access Developers discussion and problem solving'
  Onderwerp: [AccessD] Bang and Dot operator in Runtimes.

  I've been able to fix this by making some changes in code but want to
  know if anyone has additional info on why this occurs.

  Sometimes, referring to a text box with the "." operator sometimes fails
  in runtime apps.

  me.txtDate = #1/1/2001#  'Causes an error Vs.
  Me!txtDate = #1/1/2001#

  The error message I get is that the dot operator is invalid.

  I simply change it and it's fine. Yet, on other forms, it's working.

  I re-import and uncompile/compile many times on these apps and it still
  doesn't seem to always catch the potential problem.

  Any thoughts?

  John
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list