Date Time Picker and Queries

Posted on 2006-03-30
Last Modified: 2010-08-11

I have developed a DB with a simple query.  The query requires the user to enter two dates then will provide the data that is between the date range entered.  (Between [Start Date] And [End Date])  When I run the query, I get a box that asks me for the starting and ending dates, just as you would expect.  What I would like to do is use the DateTimePicker ActiveX control to select the dates instead of having to type in the date.  Does anyone know how this could be accomplished?  Is this even possible?

Question by:sbreen
    LVL 15

    Accepted Solution

    You will have to creat a new form.

    Put your date time picker as StartDate and EndDate on that form.

    Put a button on the form to run your query.

    In the query the parameters would now look like :
    Between Forms!MyForm![Start Date] And Forms!MyForm![End Date]
    LVL 3

    Expert Comment

    look at this, look at GH081410 anwser

    By the way, sometime with the between function, you have probleme with the date format. there is a trick to bypass it

    try: between clng(format(TheDateFrom,"yyyymmdd")) and clng(format(TheDateTo,"yyyymmdd"))

    Author Comment

    Could someone show me sample code for the button to run the query.
    LVL 15

    Expert Comment

    docmd.openquery "QueryName"
    LVL 18

    Expert Comment

    by:Richard Daneke
    Hi sbreen,

    jmantha709 is correct.  You need a form to use the ActiveX data picker controls and you need to refer to those dates when you run the report.  The form also needs to be open.

    When you present a form for parameters, we often offer several buttons - Print Report, Print Preview, and Cancel.  The button wizards can open the report views and cancel the report, but will not hide your form while the report runs. (A certain distraction to the end user!)

    Assuming the form is named frmDatePicker, insert the line Form_frmDatePicker.Visible = False before the visual basic line that opens the report.  You can quickly open the code window when you open event properties on each of your form buttons.

    And, in the Report OnClose event, you can add two lines:
    Form_frmDatePicker.Visible = True
    DoCmd.Close Form_frmDatePicker

    These will enable your frmDatePicker to show up on next use and will close the form as well.

    Author Comment

    Thanks jmantha709 it worked great and I will give you the much deserved points.
    LVL 15

    Expert Comment

    Glad I could help !

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    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…
    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…
    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…

    745 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

    16 Experts available now in Live!

    Get 1:1 Help Now