1

I have a button on a form that displays the current date. Very simple code:

MsgBox DATE

This worked for several months, but after some seemingly unrelated changes this stopped working and I get the error: run-time error '2465': Can't find the field "DATE' referred to in your expression.

Clearly, Access stopped recognizing DATE as a function, and is trying to find it as an object that doesn't exist. DATE() is immediately replaced by DATE by Access in the VBA code.

None of the objects in the form are named Date and none of the fields in the control source table have the name Date so I don't know why Access is confused.

When I create a new form with a button and the same code it works. Any ideas?

2 Answers 2

6

Try this:

MsgBox VBA.Date

It should point Access to the VBA built-in function instead of some field called DATE.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you this worked perfectly. I don't understand why my code worked before, but I'm glad it works now
@Carl, there must have been an issue with some VBA library over written by another library with the same function calls. eg. Date, Without specifying VBA.Date, code could be compromised.
0

Date is a data type ... use the Now method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.