Query Formula with Dates

Mudbutt

Board Regular
Joined
Jul 18, 2011
Messages
158
I have two columns in a query pulling from a table right now, one is a list of material numbers and another is for dates. I need to add a third column that is pretty much an if statement saying if the corresponding date is >= -2 months ago from today's month, then show the actual date from the date column, otherwise show text "No".

It has to be the month in it's entirety instead of like -60 days or something because I need to pick up everything from two months ago forward.

I'm new to Access and struggling with formulating this. Can anyone help?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
If I read your requirements right, something like:

NewFieldNameHere: IIf(Month(Date()) - Month(Nz([OriginalFieldNameHere],0)) >= 2, Cstr(Nz([OriginalFieldNameHere],0)), "No" )
 
Upvote 0
This formula is only showing the date from 2 months ago, and not everything forward as well. I believe it needs to take into consideration the year because i have stuff in there with dates in 2012.
 
Upvote 0
This formula is only showing the date from 2 months ago, and not everything forward as well. I believe it needs to take into consideration the year because i have stuff in there with dates in 2012.

Okay, how about:

NewFieldNameHere: IIf(DateSerial(Year([OriginalFieldNameHere], Month([OriginalFieldNameHere]), 1) > = DateSerial(Year(DateAdd("m", -2, [OrigianalFieldNameHere])), Month(DateAdd("m", -2, [OrigianalFieldNameHere])+1), 0), Cstr(Nz([OriginalFieldNameHere],0)), "No" )
 
Upvote 0
Hey Bob, it's giving me an error when i input it saying there is a comma or backet out of place somewhere. I'm having trouble identifying it.
 
Upvote 0
Sorry, I missed a paren - I THINK this should do it:

NewFieldNameHere: IIf(DateSerial(Year([OriginalFieldNameHere]), Month([OriginalFieldNameHere]), 1) > = DateSerial(Year(DateAdd("m", -2, [OriginalFieldNameHere])), Month(DateAdd("m", -2, [OrigianalFieldNameHere])+1), 0), Cstr(Nz([OriginalFieldNameHere],0)), "No" )
 
Upvote 0
It's just coping all the dates over now, the "No" isn't being shown at all. By the way, i really appreciate your efforts with this. It's been a tough one for me to figure out too.
 
Upvote 0
I figured it out with your dateadd stuff. I had never used that function before.

NR: IIf([Date]>=DateAdd("m",-2,DateSerial(Year(Date()),Month(Date()),1)),[Date],"No")
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top