Solved

Control query date criteria from a table in Access

Posted on 2014-02-10
6
611 Views
Last Modified: 2014-02-10
Hi Experts

I have a database with a number of tables which contain various project data.

Based on these tables, I've created multiple queries for monthly reporting and use a criteria range in the data field to select the records I want, e.g. >=#1/01/2014# And <#1/02/2014#.

Every month I have been editing the queries with the new date ranges before I run a DoCmd.TransferSpreadsheet module to export the data into Excel and into named ranges.

I am aware that I can control the query date criteria from an unbound form field, however ideally I would like to be able to have a table instead that contains a StartDate and EndDate field which I can change the dates each month.

Is this possible and can someone please help me with this?

I have attached an example database to assist.

Thanks
darls15
Example.accdb
0
Comment
Question by:darls15
  • 3
  • 3
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39848951
what is the month criteria of your query, if the current month is February?

you can use a criteria like this

between dateserial(year(Now()),Month(Now())-1,1) and  dateserial(year(Now()),Month(Now()),2)
0
 

Author Comment

by:darls15
ID: 39848967
Hi Rey

Thanks for getting back to me. This criteria works well however, sometimes the reports are run late due to a number of reasons (staff absense etc). For example, it could be the month of June, however the reports need to be run for the month of March. This would still mean that I would have to manually update every query to produce the report.

Any suggestions?

Thanks
darls15
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39848983
use a form with textboxes or combo box where you can select the dates.

use a criteria like this

where [datefield] between Forms!NameOfForm!StartDate and Forms!NameOfForm!endDate
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:darls15
ID: 39849142
Hi again,

Thank you I've managed to place text boxes and enabled date pickers on them and this is now working with the queries.

Also would you know if it is possible to have the date fields on the form retain the selected dates when it is closed?

darls15
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39849209
yes, you need to create a table with two fields (Start date, End Date) and make it the Record Source of the form.
0
 

Author Comment

by:darls15
ID: 39849223
got it! thank you very much, your assistance has been appreciated.
darls15
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

776 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