Solved

count records by week and month

Posted on 2009-06-30
13
774 Views
Last Modified: 2013-11-27
In relation to my previous question, i am trying to get a select count query to count records for last week, last month, last quarter and last year so i dont have to constantly change the dates in statement.

The attached statement works but will only give me the dates i specify, how can i get this query to ask for the dates in with a date calender popup?

Hope i explained myself properly.

Thanks
SELECT Count([dbo_job list].[Job Number]) AS [CountOfjobnumber], [dbo_job list].[Engineer]

FROM [dbo_job list]

WHERE [opened date] Between #21/6/2009 00:00:01# And #27/6/2009 00:00:00#

GROUP BY [dbo_job list].[Engineer];

Open in new window

0
Comment
Question by:Pickriff
  • 5
  • 5
  • 3
13 Comments
 
LVL 84
ID: 24744376
You can't do this directly in a query - that is, a query cannot "fire" events, which is what you would need to do in order to show a datetime picker.

You could, instead, build a small form that would be used to fill those dates, and then run your query. You didn't mention what version of Access you're using, but 2007 has a builtin datetime picker.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24744415
If you use parameters, it will prompt you for dates.  I use that often and works just fine; however, you have to manually type the dates in correctly as will not present a calendar/datetime picker to you, just a text box.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24744424
Syntax is like this IIRC:
SELECT Count([dbo_job list].[Job Number]) AS [CountOfjobnumber], [dbo_job list].[Engineer]

FROM [dbo_job list]

WHERE [opened date] Between [enter start date] And [enter end date]

GROUP BY [dbo_job list].[Engineer];

Open in new window

0
 
LVL 1

Author Comment

by:Pickriff
ID: 24744437
Its Access 2007, so what your saying is, create another table containing headings of start date and end date, create a form attached to this table...then   thats where i get lost.  how would i link whats in that table to the count query i want to run, also im assuming i would need to implement a little bit of VBA code? to delete the records in the start date , end table after they are used?
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24744485
Using LSMConsulting's suggestion, you would build a form.  Don't think you need a new table.  On the form, you could have the user pick start and end dates which you then use to dynamically build the query you had above with literal dates and execute.

Using my suggestion, you just run this as a query and it will prompt for the [enter start date] and [enter end date] since they are not real columns.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 24744515
Create a form with two textboxes: txtStartDate and txtEndDate, and make sure to set the "Show Date Picker" property to "For Dates". Now add a button to your form, and set the Click event to this:

DoCmd.OpenQuery "YourQueryName"

Change your query to "look" at this form:

SELECT Count([dbo_job list].[Job Number]) AS [CountOfjobnumber], [dbo_job list].[Engineer]
FROM [dbo_job list]
WHERE [opened date] Between #" & Forms!YourFormName.txtStartDate & "# AND #" & Forms!YourFormName!txtEndDate & "#"
GROUP BY [dbo_job list].[Engineer];


I don't think the form has to be connected to a table - the DateTime picker should show, but you may have to change the "For Dates" value to something else ...
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 1

Author Comment

by:Pickriff
ID: 24744777
Hi Im getting a Syntax error 3075 doesnt seem to like theend of the third line

WHERE [opened date] Between #" & Forms!YourFormName.txtStartDate & "# AND #" & Forms!YourFormName!txtEndDate & "#"

The latter of the above line of code Forms!YourFormName!txtEndDate, that should be Forms!YourFormName.txtEndDate?  Ive tried it anyway and get same error
0
 
LVL 84
ID: 24744793
I'm assuming that you changed YourFromName to, obviously, the name of the form you're using?
0
 
LVL 1

Author Comment

by:Pickriff
ID: 24744820
Yes, had a little play with the code, and i cant seem to get it to run, this has an SQL backend so im not sure if this will make any difference
0
 
LVL 84
ID: 24744837
Yes, that could ...

What exactly are you trying to do with the query? Do you want users to be able to simply view the data? Or is this being used to open a Form or Report.
0
 
LVL 1

Author Comment

by:Pickriff
ID: 24745053
Its to create a report to show how many jobs have been opened within a set time period, i want to do a second one that will report on how many of those have been closed or completed with the prioritised SLA, i know thats probably quite complicated, so im trying to take it a step at a time
0
 
LVL 1

Author Closing Comment

by:Pickriff
ID: 31598305
Thankyou for your answer, having reverted back to access db it now works however no further info was provided on an SQL backend hence the C grade

THanks
0
 
LVL 84
ID: 25424946
Thanks for the "C" grade ... I'll certainly make note of that. I'm sure the other Experts can provide you sufficient assistance, as I'll not take any additional time with you.
0

Featured Post

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)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prevent use of Microsoft Office application 9 55
Query design issue 2 24
Access Query based on a Form Field 2 21
How autonumber field on a form 16 19
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…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…

863 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