[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert Current Date Using VBA

Posted on 2011-05-12
3
Medium Priority
?
780 Views
Last Modified: 2013-11-27

I'm just trying to insert today's date in the date field when double clicking in the date field. This code work's perfectly in other sections on my database. Not sure what is wrong with this one?

I get 'Runtime Error 2465- Office can't find the field date referred to in your expression'. Why is it looking for a field? If I change the code to: Me.CommentsDate = Now(), that works perfectly. I only want the date though, not time as well. Any suggestions please?
Private Sub CommentsDate_DblClick(Cancel As Integer)
If MsgBox("Would you like to insert today's date?", vbQuestion + vbYesNo, "Insert Today's Date") = vbYes Then
Me.CommentsDate = Date
End If
End Sub

Open in new window

0
Comment
Question by:jammin140900
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 35745768
check your References, look for references prefixed by "MISSING:"

do a Debug > Compile
correct any errors raised.

you can try using

Me.CommentsDate = Datevalue(Now())
0
 
LVL 3

Expert Comment

by:mburazor
ID: 35745810
check textbox (CommentsDate) formating
make sure that format is formated as long, short or general date

check control source of textbox if it has control source check field definition in table

otherwise code should work
0
 

Author Comment

by:jammin140900
ID: 35746081
Thanks for the suggestions.

Capricorn, I looked for missing references (there was none), compiled and still had the problem. Tried your second alternative and it worked beautifully. Just out of curiosity, I removed yours and re-entered just = date.

Suddenly its starts working again. How frustrating! - Thanks though.

Thanks mburazor. I checked all of those before posting this request. Wasn't sure why the code wouldn' work as I've used the same thing so many times over the years. Thanks for the suggestions though.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question