Re: problem getting a value from Date()



Your code should work. Your MsgBox example should be:

? MsgBox(Date())
or
? MsgBox(Date)

You can't use a msgbox as a statement in the Immediate Window, you need to
use the function.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Paul" <begone@xxxxxxxx> wrote in message
news:%23oZnB%23YrIHA.1772@xxxxxxxxxxxxxxxxxxxxxxx
I'm trying to write a line of code that will update a date field (txtDate)
in a form to the current date whenever a value in another field is
changed. To that end, I've tried using the following:

Private Sub Activity_AfterUpdate()
Me!txtDate = Date()
End Sub

but it doesn't do anything. That is, it doesn't enter today's date in
txtDate.

I've also noticed that in the Immediate pane, ?Date() produces the current
Date, but MsgBox Date() produces an error becuase Date() is null.

Why does VBA recognize Date() in the immediate pane as having a value of
today's date, while the MsgBox function thinks it has no value? And what
can I do to reset txtDate to today's date whenever the value in the
Activity field is updated?

Thanks in advance,

Paul



.



Relevant Pages

  • Re: problem getting a value from Date()
    ... I didn't mean to suggest that I tried using MsgBox Datein the Immediate ... I only used ?Datein the Immediate Window, ... Private Sub Activity_AfterUpdate ...
    (microsoft.public.access.formscoding)
  • Re: problem getting a value from Date()
    ... I didn't mean to suggest that I tried using MsgBox Datein the Immediate ... I only used ?Datein the Immediate Window, ... txtDate. ...
    (microsoft.public.access.formscoding)
  • Re: problem getting a value from Date()
    ... The point I was trying to make about getting ?Date to work in the Immediate ... Window while Me!txtDate = Dateproduces an "Invalid Outside Procedure" ... I didn't mean to suggest that I tried using MsgBox Datein the Immediate ...
    (microsoft.public.access.formscoding)
  • Re: New If Statement Post
    ... Block If without End If is the error message I get in the immediate ... MsgBox "Why is there more material on this job?" ... > in the Immediate window when execution reaches the If statement... ...
    (microsoft.public.access.forms)
  • Iserror with Search
    ... I am trying to test a string in VBA to see if it exists using the following: ... If I use the msgbox in the immediate pane to see the result I get ...
    (microsoft.public.excel.programming)