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

Posted on 2009-02-19
Medium Priority
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
  • 2
LVL 28

Accepted Solution

TextReport earned 300 total points
ID: 23689832
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

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

Expert Comment

ID: 23690401

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

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

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

592 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