Expressions in Access 2003

  • Thread starter Thread starter Boris
  • Start date Start date
B

Boris

I try to write the current date to a text field in a form when I click on
the text field. I use the expression "=Date()" but it does not work. There
is no error message but no date either. I tried "=MsgBox('hello')" which is
executed (so expressions seem to work in general). What do I have to do to
change the value in a text field using expressions (in Access 2003)?

TIA,
Boris
 
This worked for me:

Me!Text0.Text = Date

--
Rebecca Riordan, MVP

Designing Relational Database Systems
Microsoft SQL Server 2000 Programming Step by Step
Microsoft ADO.NET Step by Step

http://www.microsoft.com/mspress

Blessed are they who can laugh at themselves,
for they shall never cease to be amused...
 
Rebecca said:
This worked for me:

Me!Text0.Text = Date

This is VBA and not an expression, isn't it? Expressions have to start with
an equal sign? But "=Date()" doesn't work for you either?
Maybe I am wrong as it is some time ago that I used Access but I wonder why
I can't use a simple "=Date()" expression to put the current date in a text
field? This is how expressions are supposed to work?

Boris
 
Boris,

You can, but you have to enter =Date() into the textbox's DefaultValue
property. Doing so will put today's date in its Value property only if the
field to which the control is bound does not contain a value.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Boris said:
Rebecca said:
This worked for me:

Me!Text0.Text = Date

This is VBA and not an expression, isn't it? Expressions have to start with
an equal sign? But "=Date()" doesn't work for you either?
Maybe I am wrong as it is some time ago that I used Access but I wonder why
I can't use a simple "=Date()" expression to put the current date in a text
field? This is how expressions are supposed to work?

Boris
 
Graham said:
Boris,

You can, but you have to enter =Date() into the textbox's DefaultValue
property. Doing so will put today's date in its Value property only
if the field to which the control is bound does not contain a value.

Ah, thanks, that worked! But can expressions be used at all with events?
They don't seem to work then? Is it better to use macros?
So is this a bug or by design that "=Date()" does not work as expected with
the onclick-event?

Boris
 
Boris,

Date() is a VBA function, which means it works anywhere the expression
service works, which includes events.

If you want the date to appear when you click in the textbox, use Rebecca's
suggestion:
Me!Text0.Text = Date

....where Text0 is the name of your textbox.

If you want to do the same thing while Text0 does NOT have the focus, use:
Me!Text0 = Date

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Boris said:
Graham said:
Boris,

You can, but you have to enter =Date() into the textbox's DefaultValue
property. Doing so will put today's date in its Value property only
if the field to which the control is bound does not contain a value.

Ah, thanks, that worked! But can expressions be used at all with events?
They don't seem to work then? Is it better to use macros?
So is this a bug or by design that "=Date()" does not work as expected with
the onclick-event?

Boris
 
Back
Top