date choice

pastorkc

Board Regular
Joined
Jan 29, 2020
Messages
125
Office Version
  1. 2010
Platform
  1. Windows
Is there a way in access either by query or report to have the user select a date range before the query is run? For example the user wants to run a report for a specific fiscal year.
 
What do you mean "combined query"?
Are you combining it with something else?
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I did a union between my two tables and it was working but when I replaced it with the new code it stopped working, but the others are working with the new code. I updated the code for the union query but it isn't working.
 
Upvote 0
In your UNION queries, do you have the exact same field names in the exact same order, in each of the two queries you are trying to join together?
Also, do you have any blank or error values in your Date field in each underlying query?
 
Upvote 0
yes exactly the same order and same fields. No blank or error fields.
 
Upvote 0
What are the names of the two underlying queries and the Union query?
Are they all found in the database you uploaded?
 
Upvote 0
Yes they are. One is Combined Query. The two that are linked are Fiscal_Year-Fixed and Fiscal_Year-TODD.
 
Upvote 0
Please change your Union query to SQL view and copy and paste the SQL code here.
 
Upvote 0
SELECT Category.*, Year([Date]) AS CalendarYear, Month([Date]) AS CalendarMonth, IIf(Month([Date])<7,Year([Date]),Year([Date])+1) AS Fiscal_Year, MonthName([CalendarMonth],False) AS MonthName
FROM Category
WHERE (((IIf(Month([Date])<7,Year([Date]),Year([Date])+1))>=[Start Fiscal Year] And (IIf(Month([Date])<7,Year([Date]),Year([Date])+1))<=[End Fiscal Year]))
ORDER BY Month([Date])

UNION

SELECT [TODD Category].*, Year([Date]) AS CalendarYear, Month([Date]) AS CalendarMonth, IIf(Month([Date])<7,Year([Date]),Year([Date])+1) AS Fiscal_Year, MonthName([CalendarMonth],False) AS MonthName
FROM [TODD Category]
WHERE (((IIf(Month([Date])<7,Year([Date]),Year([Date])+1))>=[Start Fiscal Year] And (IIf(Month([Date])<7,Year([Date]),Year([Date])+1))<=[End Fiscal Year]))
ORDER BY Month([Date]);
 
Upvote 0
Try replacing the current SQL code with this:
Rich (BB code):
SELECT Category.*, Year([Date]) AS CalendarYear, Month([Date]) AS CalendarMonth, IIf(Month([Date])<7,Year([Date]),Year([Date])+1) AS Fiscal_Year, MonthName([CalendarMonth],False) AS MonthName
FROM Category
WHERE (((IIf(Month([Date])<7,Year([Date]),Year([Date])+1))>=[Start Fiscal Year] And (IIf(Month([Date])<7,Year([Date]),Year([Date])+1))<=[End Fiscal Year]))
UNION
SELECT [TODD Category].*, Year([Date]) AS CalendarYear, Month([Date]) AS CalendarMonth, IIf(Month([Date])<7,Year([Date]),Year([Date])+1) AS Fiscal_Year, MonthName([CalendarMonth],False) AS MonthName
FROM [TODD Category]
WHERE (((IIf(Month([Date])<7,Year([Date]),Year([Date])+1))>=[Start Fiscal Year] And (IIf(Month([Date])<7,Year([Date]),Year([Date])+1))<=[End Fiscal Year]))
ORDER BY 8;
 
Upvote 0
Try replacing the current SQL code with this:
Rich (BB code):
SELECT Category.*, Year([Date]) AS CalendarYear, Month([Date]) AS CalendarMonth, IIf(Month([Date])<7,Year([Date]),Year([Date])+1) AS Fiscal_Year, MonthName([CalendarMonth],False) AS MonthName
FROM Category
WHERE (((IIf(Month([Date])<7,Year([Date]),Year([Date])+1))>=[Start Fiscal Year] And (IIf(Month([Date])<7,Year([Date]),Year([Date])+1))<=[End Fiscal Year]))
UNION
SELECT [TODD Category].*, Year([Date]) AS CalendarYear, Month([Date]) AS CalendarMonth, IIf(Month([Date])<7,Year([Date]),Year([Date])+1) AS Fiscal_Year, MonthName([CalendarMonth],False) AS MonthName
FROM [TODD Category]
WHERE (((IIf(Month([Date])<7,Year([Date]),Year([Date])+1))>=[Start Fiscal Year] And (IIf(Month([Date])<7,Year([Date]),Year([Date])+1))<=[End Fiscal Year]))
ORDER BY 8;
That worked, Thank you. Can I ask why you put ORDER BY with an 8?
 
Upvote 0

Forum statistics

Threads
1,215,101
Messages
6,123,095
Members
449,095
Latest member
gwguy

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