473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Building Instant Reports By Date

Hello,

I'm building a tracking tool using Access 2003, where my users will be entering orders that includes quantity of products sold, and cost per unit.

I'm in the process of building several instant reports where they can click on a control without having to specific any criterias such as data ranges and pull up an instant report

What I'm having trouble with is building reports that will compute totals by certain dates (Totals For Last Week, Totals For Last Month) based on the run date.

What is the best way to build a query that will automatically locate a weekly or monthly date range based on the run date
For example: If I run a report today (6/22/2007) for last week's data, I want to write a script to query records between (6/10/2007 - 6/16/2007)
Jun 23 '07 #1
4 2156
ADezii
8,834 Expert 8TB
Hello,

I'm building a tracking tool using Access 2003, where my users will be entering orders that includes quantity of products sold, and cost per unit.

I'm in the process of building several instant reports where they can click on a control without having to specific any criterias such as data ranges and pull up an instant report

What I'm having trouble with is building reports that will compute totals by certain dates (Totals For Last Week, Totals For Last Month) based on the run date.

What is the best way to build a query that will automatically locate a weekly or monthly date range based on the run date
For example: If I run a report today (6/22/2007) for last week's data, I want to write a script to query records between (6/10/2007 - 6/16/2007)
Based on a Run Date of 6/22/2007, the following code will dynamically create a Query based on a ficticious Table which will return all Records between the Range of 6/10/2007 and 6/16/2007 (10 days prior to Run Date to 6 days prior to Run Date). The code makes the hugh assumption that the Run Date is on a Friday and is based on your beginning and ending specifications. Any questions, feel free to ask:
Expand|Select|Wrap|Line Numbers
  1. Dim dteRunDate As Date, dteStartDate As Date
  2. Dim dteEndDate As Date, MySQL As String
  3. Dim MyDB As DAO.Database, qdf As DAO.QueryDef
  4.  
  5. Set MyDB = CurrentDb()
  6.  
  7. For Each qdf In MyDB.QueryDefs
  8.   'Create your own Query Name
  9.   If qdf.Name = "Orders For Date Range" Then
  10.     MyDB.QueryDefs.Delete qdf.Name
  11.   End If
  12. Next
  13.  
  14. dteRunDate = #6/22/2007#
  15. dteStartDate = DateAdd("d", -12, dteRunDate)
  16. dteEndDate = DateAdd("d", 6, dteStartDate)
  17.  
  18. 'substitute your own Table and Field Name 
  19. MySQL = "Select * From tblTableName Where [Your_Date_Field] Between #" & dteStartDate & "# And #" & dteEndDate & "#;"
  20.  
  21. 'if different, must match the Query Name you deleted above
  22. Set qdf = MyDB.CreateQueryDef("Orders For Date Range", MySQL)
  23.  
  24. RefreshDatabaseWindow
  25.  
  26. Set qdf = Nothing
Jun 25 '07 #2
Thank you for responding. The issues I have with this method is the following: I don't want to hard code the "run date" because this will frequently change. This will affect the parameters passed to the DateAdd function

dteRunDate = #6/22/2007#
dteStartDate = DateAdd("d", -12, dteRunDate)
dteEndDate = DateAdd("d", 6, dteStartDate)

Also, I rather use the ADO library because I'm running this procedures using data with a SQL Server database and I'm looking to convert this into a web app.
Jun 30 '07 #3
FishVal
2,653 Expert 2GB
Thank you for responding. The issues I have with this method is the following: I don't want to hard code the "run date" because this will frequently change. This will affect the parameters passed to the DateAdd function

dteRunDate = #6/22/2007#
dteStartDate = DateAdd("d", -12, dteRunDate)
dteEndDate = DateAdd("d", 6, dteStartDate)

Also, I rather use the ADO library because I'm running this procedures using data with a SQL Server database and I'm looking to convert this into a web app.
Try to use the following

Expand|Select|Wrap|Line Numbers
  1. dteStartDate = DateAdd("d", -Weekday(dteRunDate) - 7, dteRunDate)
  2. dteEndDate = DateAdd("d", -Weekday(dteRunDate), dteRunDate)
  3.  
Jun 30 '07 #4
ADezii
8,834 Expert 8TB
Thank you for responding. The issues I have with this method is the following: I don't want to hard code the "run date" because this will frequently change. This will affect the parameters passed to the DateAdd function

dteRunDate = #6/22/2007#
dteStartDate = DateAdd("d", -12, dteRunDate)
dteEndDate = DateAdd("d", 6, dteStartDate)

Also, I rather use the ADO library because I'm running this procedures using data with a SQL Server database and I'm looking to convert this into a web app.
The issues I have with this method is the following: I don't want to hard code the "run date" because this will frequently change.
I rather use the ADO library because I'm running this procedures using data with a SQL Server database and I'm looking to convert this into a web app
  1. The Run Date was hard coded for demo purposes only.
  2. Whether you use DAO or ADO would not effect the basic logic, only the syntax.
Jun 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: PatchFactory Support | last post by:
Description: Professional and easy-to-use patch building environment that can help you to create instant patch packages for software and file updating. Generated patch packages are small size...
0
by: Lynda Kilgore | last post by:
jGu ----qtHwhORV90yyhqJMOc Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html><head><style type=3Dtext/css>.eyebrow { FONT-WEIGHT: bold; FONT-SIZE= : 10px;...
7
by: SharkSYA | last post by:
After canvassing ideas it appears that the way I need to do it is not possible.There are 126 rooms, more to be added, and it needs to print a report or reports showing 76 days of bookings. There...
2
by: Rene | last post by:
I have a master "attendance" report that also has two "attendance" sub-reports...each collecting data from a different group...and totaling those present at the end. I chose sub-reports because...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
10
by: jerry.ranch | last post by:
I get extracts/reports from a corporate Sybase database. This is a very very large transactional database, very little (or slow and complex) reports/queries, so instead I have an all-inclusive...
7
by: rzagars | last post by:
I have just started working on DB2 which the syntax is a lot different. I am trying to create a SQL stored procedure for generating reports. I want to use temporary database which in this example...
3
by: wsox66 | last post by:
I am new to Access and need some help building a report. I have looked through previous posts on reports but none of them seem to answer my question completely. I am using Access 2003 and I have...
4
by: shahidrasul | last post by:
hi i have a object to a user defined class which properly intialized from class when first form load, but after post back it loose reference and such error occured ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.