Date() in a form module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dixie

    Date() in a form module

    Just a general question to satisfy my natural curiosity. I have noticed
    that when I type Date() as part of a procedure behind a form, the ()
    brackets drop off the end of it immediately I type them. It does, however
    appear to work as though they were there.

    Does this mean that I shouldn't use Date as a field name in a procedure as
    today's date - Date() ends up as Date after the brackets disappear?

    dixie


  • Allen Browne

    #2
    Re: Date() in a form module

    Date is a reserved word. In VBA it stands for the system date. You can both
    read and assign its value.

    There is also a Date() function that you can use in other contexts, such as
    in the ControlSource of a text box in in the Criteria of a query. As you
    found, if you use the Date() function in a module, VBA replaces it with the
    Date statement.

    It is important to avoid using reserved words such as Date as field names.
    If you do, your code is likely to be ambiguous, so the results may be
    different from what you intend. Always use another name, such as OrderDate.

    Also avoid using the names of built-in properties. For example, almost
    everything in Access has a Name property, so if you create a field called
    "Name" Access is likely to misunderstand the reference because Me.Name is
    the name of the form. The same happens with Section (because forms have a
    Section), etc.

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "dixie" <dixiec@dogmail .com> wrote in message
    news:s36cc.45$2 Y3.2657@nnrp1.o zemail.com.au.. .[color=blue]
    > Just a general question to satisfy my natural curiosity. I have noticed
    > that when I type Date() as part of a procedure behind a form, the ()
    > brackets drop off the end of it immediately I type them. It does, however
    > appear to work as though they were there.
    >
    > Does this mean that I shouldn't use Date as a field name in a procedure as
    > today's date - Date() ends up as Date after the brackets disappear?[/color]


    Comment

    Working...