473,473 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Automate Dates 1-3/ 3-6 / 6-9 / 9-12

72 New Member
I’m looking for a way that I can automate my dates. Instead of going in a couple of times a months going into my query and changing the dates to correct my query.

My typically query outcomes are.
  1. Past 3 months starting at the end of the prior month and go back 3 months.
    Past 6 months starting at the end of the prior month and go back 6 months.
    Past 9 months starting at the end of the prior month and go back 9 months.
    Past 12 months starting at the end of the prior month and go back 12 months.
  2. List Item

I tried using the formula below, but seem to be pulling by quarters, and if I need to pull a report that shows the past 3 month and I’m half way through the 4th month it doesn’t let me pull the correct data

Expand|Select|Wrap|Line Numbers
  1. 3Month: Sum(IIf([Data_Field]>DateAdd("m",-3,Date()),[Amount_Actual_Loan],0))
  2.  
  3. 6Month: Sum(IIf([Data_Field]>DateAdd("m",-6,Date()),[Amount_Actual_Loan],0))
  4.  
  5. 9Month: Sum(IIf([Data_Field]>DateAdd("m",-9,Date()),[Amount_Actual_Loan],0))
  6.  
  7. 12Month: Sum(IIf([Data_Field]>DateAdd("m",-12,Date()),[Amount_Actual_Loan],0)) 
Thank you for all you time and help
TCB
Dec 28 '10 #1
1 1056
ADezii
8,834 Recognized Expert Expert
The tricky part is that you are starting from the Last Day of the Previous Month and going backwards. Here is the required Logic, as I see it:
Expand|Select|Wrap|Line Numbers
  1. Dim dteDate As Date
  2.  
  3. dteDate = #12/28/2011#
  4.  
  5. Debug.Print "*************************************************************"
  6. Debug.Print "Date:" & dteDate
  7. Debug.Print "Last date of Previous Month: " & DateSerial(Year(dteDate), Month(dteDate), 1) - 1
  8. Debug.Print "3 Months Prior to Last Day of Previous Months: " & _
  9.              DateAdd("m", -3, DateSerial(Year(dteDate), Month(dteDate), 1) - 1)
  10. Debug.Print "*************************************************************"
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. *************************************************************
  2. Date:12/28/2011
  3. Last date of Previous Month: 11/30/2011
  4. 3 Months Prior to Last Day of Previous Months: 8/30/2011
  5. *************************************************************
Dec 28 '10 #2

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

Similar topics

10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
2
by: Keith | last post by:
There are certain records I create which are open and shut. That is, we don't put a completion date in that record. I would like to automate this and with certain records, take the date created...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
11
by: gert365 | last post by:
I'm working on a scirpt to be used on a windows machine and I need to automate a user's input on the command prompt. For example I'm using os.system('mycommand') to excute the commands I want. ...
9
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
2
by: Jim Carlock | last post by:
(1) Does PHP provide any way to handle dates prior to 1980? I know there's problems with Microsoft Windows NT and all Windows NT operating systems will allow a date prior to 1980 to be placed...
2
by: =?Utf-8?B?QWxleGFuZGVyIFd5a2Vs?= | last post by:
Is it possible to automate a COM object ebmeded in an excel document run the process and return the results in a C# .NET application? Or better yet extract the com object some how and just run it...
1
by: junkax | last post by:
1. when I export a query, can I specify just for column1 to be exported and not the other columns 2. can I specify some text to be added to top of the output file? something like this: t...
7
by: Bre035 | last post by:
I am creating a Year to Date report. Typically, I create a query to allow the ability to enter the beginning and end date, but I want to automate this without entering the date. I have criteria...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.