Insert Current Date Using VBA

Posted on 2011-05-12
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

Question by:jammin140900
    LVL 119

    Accepted Solution

    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())
    LVL 3

    Expert Comment

    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

    Author Comment

    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.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now