More elegant way to convert text to dates in MS access?

Posted on 2009-02-19
Last Modified: 2013-11-28
I have a form to input info for a query.  Every thing works, but just out of personal development, I'm curious if there's a more elegant way to convert text box inputs to dates.  

A user selects a month [reportmoth] and year [reportyear] from a form [fq-form] .  This is then compared to a field [response date] in the data table with the following criteria using the Cdate () function:

Between CDate([forms]![fq-form]![reportmonth] & " 1, " & [forms]![fq-form]![reportyear]) And CDate([forms]![fq-form]![reportmonth] & " 31, " & [forms]![fq-form]![reportyear])

It works, but in MS Excel i could say something like month([response date]) = [reportmonth] AND year([response date]) = [report year]  

Is there an equivalent in MS access?  
Question by:ppontius
    LVL 28

    Accepted Solution

    In Access you have both Month and Year functions that return the value from the date, however, to make your queries run as efficiently as possible you should not do anything on the lect of the comparison (in this case =), therefore

    Between CDate([forms]![fq-form]![reportmonth] & " 1, " & [forms]![fq-form]![reportyear]) And CDate([forms]![fq-form]![reportmonth] & " 31, " & [forms]![fq-form]![reportyear])

    Will be more efficient than

    month([response date]) = [reportmonth] AND year([response date]) = [report year]

    even though it doesn't look as elegant.

    You may find using DateSerial a bit more elegant

    Between DateSerial([forms]![fq-form]![reportyear], [forms]![fq-form]![reportmonth], 1) And DateSerial([forms]![fq-form]![reportyear], [forms]![fq-form]![reportmonth], 31)

    This requires Month to be a number.

    Cheers, Andrew

    Author Comment

    interesting.  I guess efficiency is better than elegance in this case.  
    LVL 28

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    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…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now