473,396 Members | 1,990 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,396 software developers and data experts.

Finding all records before todays date - 5 Days

Hey Guys,

Currently I'm using a code to find all records before a certain date.

I'm using
If LogDate < Date -5 Then

The problem with this is, Its only filtering by Day not month or year.

For example, It'll show all records like this
Shows 01/02/2011 - 07/02/2011
But not 08/02/2011 - 28/02/2011
Shows 01/03/2011 - 07/03/2011
But not 08/03/2011 - 31/03/2011

Any way I can set it to include the month/year in the date calculation so it excludes records from only the last five days?

Thanks in Advance.
Apr 12 '11 #1
9 2446
TheSmileyCoder
2,322 Expert Mod 2GB
It sounds a bit odd to me. Is logDate a date/time variable? Can you include any code where you dim and/or manipulate it?
Apr 12 '11 #2
The code I'm using is this.

Expand|Select|Wrap|Line Numbers
  1. Public Function JobsDateFive(LogDate As String, ComDate As String, StatBox As String, TypeBox As String) As String
  2. If LogDate < Date - 5 Then
  3. If StatBox <> "Completed" Then
  4. If StatBox <> "Cancelled" Then
  5. If StatBox <> "Invoiced" Then
  6. If StatBox <> "Resolved" Then
  7. If StatBox <> "Attended" Then
  8. If ((TypeBox = "CSTM01") Or (TypeBox = "CSTM02")) Then
  9. JobsDateFive = "1"
  10. Else
  11. JobsDateFive = "0"
  12. End If
  13. End If
  14. End If
  15. End If
  16. End If
  17. End If
  18. End If
  19. End Function
  20.  
Apr 12 '11 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Why are you passing your LogDate as a string? Its like comparing apples to elephants. You might get lucky and Access will guess the correct conversion from date->string->Date but it is bound to give you grief, and is most likely the cause of your current dilemma.

And you could simplify your code by including them in the same if statements, instead of nesting them.:
Expand|Select|Wrap|Line Numbers
  1. If StatBox <> "Completed" AND StatBox <> "Cancelled" AND StatBox <> "Invoiced" AND StatBox <> "Resolved" AND StatBox <> "Attended" Then
Apr 12 '11 #4
Hey Smiley,

Thanks for that... Was having a hard time but that totally fixed it. I've ordered a book on VBA as my new job seems to be requiring a lot of VBA coding.

Once again, Thanks
Apr 12 '11 #5
TheSmileyCoder
2,322 Expert Mod 2GB
You are most welcome. Access can be quite forgiving in alot of cases, when it comes to using the correct variable type, but in my experience it will almost always cause you grief not to declare the variable type and think about using the correct variable type.
Apr 12 '11 #6
Okay, Ill keep that in mind!
Is there any Books/Documentation you recommend reading? I studied VBA at college but this was quite a long time ago!
Apr 12 '11 #7
TheSmileyCoder
2,322 Expert Mod 2GB
The only VBA book I've read was "VBA for dummies", and then I've had alot of help from the guys and girls on this forum, as well as painstaking amounts of trial and error.
Apr 12 '11 #8
Well, I guess i'm on the right tracks.
I've just ordered Access VBA 2007 for Dummies, Think That'll help?
Apr 12 '11 #9
TheSmileyCoder
2,322 Expert Mod 2GB
I found it to be a very good start. The rest you can learn as you go along. Ill be honest and admit though, that looking back at my first coding projects 2˝ year, I would do alot differently now, but thats experience, which you can't read your way into.
Apr 12 '11 #10

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

Similar topics

6
by: Gerry Viator | last post by:
Hi all, I have a textbox were a time is typed in like: upto 4 numbers 1900 300 1000 1425 I would like as they type the text to show todays date plus the time they
3
by: Gary | last post by:
Sorry to waste everyone's time with a query which is so simple, but as a new user of Access I have created a client database and one of the fields is "next contact due" as the name implies, this is...
2
by: Chuck | last post by:
Using a macro to output a query to an Excel file. Is there a way to automatically add todays date in the file spec? As: C:\Access Data\ & todays date.xls Chuck ....
2
by: rivka.howley | last post by:
I wrote some code that creates a table with a date/time field at 15-minute intervals. Here's how I create and populate the table With tblDataTemp ..Fields.Append .CreateField("CT_ID", dbLong)...
5
by: Vayse | last post by:
In VB6, I would have used Date() That no longer works. How do I find todays date in VB.net?
2
by: Drum2001 | last post by:
Hello, I am having isues with the following: I have two forms, a MAIN FORM with a SUB FORM: Within the MAIN FORM, I have an unbound textbox (Date Format) and a command button. Onload, the...
2
by: kbaisch | last post by:
I have this code set up but I know the 3rd line is wrong. Could someone please help me on the code for pulling all entries for todays date -90 days? I would really appreciate it and thanks for...
3
by: jonosborne | last post by:
Hi guys, im a bit of a novice being thrown in at the deep end ! Using MS Access 97 i have a table with data that is updated once a day from an Excel spreadsheet. I need a way of identifying when data...
1
by: geethaandyou | last post by:
I Need A C Program To Find The Date That Comes After N Days From Todays Date
1
by: phpmel | last post by:
Hi guys, I have an asp calendar control, text box, calendar icon, eraser icon all within an update panel. The calendar works fine, postbacks are handled without the flickering of the screen etc....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.