Re: problem getting a value from Date()



"Paul" <begone@xxxxxxxx> wrote in message
news:uCzSDdZrIHA.2520@xxxxxxxxxxxxxxxxxxxxxxx
Thanks for replying to my message, Arvin, but in fact the code doesn't
work.

I didn't mean to suggest that I tried using MsgBox Date() in the Immediate
Window. I only used ?Date() in the Immediate Window, and it does work.

I tried using

MsgBox Date

in the VBA procedure in an effort to debug the problem, but it produces
the error "Invalid Outside Procedure."

I get the same error "Invalid Outside Procedure"when I try to use

Me!txtDate = Date()

in the code as well.

Can anyone tell me why I'm getting this error message when I try to use
the Date function in this procedure?

Thanks
Paul


"Arvin Meyer [MVP]" <a@xxxxx> wrote in message
news:O0wuySZrIHA.1316@xxxxxxxxxxxxxxxxxxxxxxx
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

To you it may seem that your debugging code is inside a procedure, bit it
isn't. Check that all your Sub and Function procedures are correctly
declared and terminated, ie:

Sub Something()
'Code
End Sub

Function SomethingElse()
'Code
End Function

Also look for 'orphaned' terminators, like an End Sub line with no
corresponding Sub Something() line above it.


.



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, ... txtDate. ...
    (microsoft.public.access.formscoding)
  • Problems creating an exchange mailbox and setting permissions
    ... Exchange Mailbox the rest is working fine. ... sub Window_Onload ... msgbox "Please enter the users First Name" ... msgbox "Please select the Account Type" ...
    (microsoft.public.scripting.vbscript)
  • Re: Unable to add "X-Header" to a mail that is being sent...
    ... MsgBox "Initialize Event Handlers successful" ... Private Sub Command1_Click ... It shows howw to change the "From" header, ... ChangeHeader() from my ItemSend event handler, ...
    (microsoft.public.outlook.program_vba)
  • Re: Unable to add "X-Header" to a mail that is being sent...
    ... MsgBox "Initialize Event Handlers successful" ... Private Sub Command1_Click ... It shows howw to change the "From" header, but it is equally applicable to ... ChangeHeader() from my ItemSend event handler, ...
    (microsoft.public.outlook.program_vba)
  • Re: Protection & SpellCheck in Merged Forms
    ... If the message boxes are not appearing then the MsgBox statements are almost ... putting MsgBox statements at the beginning and end of that Sub ... i.e. use a macro to unprotect the document, spell check, then reprotect, ...
    (microsoft.public.word.mailmerge.fields)