report options via query options (1 Viewer)

rainbows

Registered User.
Local time
Today, 14:47
Joined
Apr 21, 2017
Messages
425
hi ,
I have a query that has 2 date fields ( target date) format "23-May-18"
and an expression field "May 2018" not sure if I need that or not for what I am tying to do

is it possible to run the same query that can give me any 1 of 2 results depending on which one selected

1. report on the month I run the query in .

2. let the query just run and report on all the months

thanks
steve
 

Ranman256

Well-known member
Local time
Today, 17:47
Joined
Apr 9, 2015
Messages
4,337
I too use 2 formats of 1 date field in the query, for sorting purposes.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:47
Joined
Feb 28, 2001
Messages
27,183
I am going to jump to conclusions (but it might be confusions) here. My ambiguity is that I had to read the question twice before I caught a second way to understand what you are asking.

Here is the difference between your #1 and #2 questions. The difference is that #1 has a WHERE clause to restrict selection of dates. #2 does not. So a static query could be made to do both of those things, but it would be tricky.

My thought is to make TWO queries. Make the first one that gives you every month. It is easier to write. Now COPY that query to make a new query with a different name. Add the WHERE clause to the copy. You then run whichever query you need - the "get it all" version or the "get recent" version.

The "get recent" version MIGHT look vaguely like this.

Code:
SELECT [I]field1, field2, field3, ...[/I] FROM [I]mytable[/I] WHERE [I]mydatefield[/I] > ( Date() - DatePart("d", Date() ) ) ;

This takes the current date and subtracts the number of days represented by today's date from the full date. So on the 10th of the month, it subtracts 10 from the date. This gives you the last day of the previous month, so you use ">" rather than ">=" to select the dates.
 

isladogs

MVP / VIP
Local time
Today, 22:47
Joined
Jan 14, 2017
Messages
18,219
Or you can use a single query with a parameter input:
Select Month (or leave blank to select all)

Either method will work. Use whichever you find easier to understand.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:47
Joined
Feb 19, 2002
Messages
43,275
A start and end date is the most flexible. If you want to ensure that the range is full months, check the dates before applying the criteria.

Where SomeDate Between Forms!yourform!StartDate and Forms!Yourform!EndDate

PS - formatting a date turns it into a string which makes it act like a string rather than a date. NEVER format dates except for display to avoid issues.
 

rainbows

Registered User.
Local time
Today, 14:47
Joined
Apr 21, 2017
Messages
425
hi,

if I have 2 queries would I not need 2 reports?

I was hoping that I was able to use one report and if I ignored the prompt in the query all the results where shown if I used the prompt then just that month was shown

if that is not possible or does it have to be done with a macro

thanks
steve
 

isladogs

MVP / VIP
Local time
Today, 22:47
Joined
Jan 14, 2017
Messages
18,219
In this situation, I also use start date and end date textboxes together with an All Dates button
However if preferred you could use a combo for month & year together with the button.

In either case the idea is that the selection made is used to build a WHERE clause for your report record source SQL. Only one report is needed
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:47
Joined
Feb 19, 2002
Messages
43,275
If you use my suggestion, you would have ONE query.
 

rainbows

Registered User.
Local time
Today, 14:47
Joined
Apr 21, 2017
Messages
425
hi
I have been travelling to china so had no time to look at the response you all sent me of which I appreciate

Pat

I am new to this so just learning
are you telling me to put this in my query

Where SomeDate Between Forms!yourform!StartDate and Forms!Yourform!EndDate


my form name is "issue details " my table name in "Issues"


so how do I write that

thanks for all your help


steve
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:47
Joined
Feb 19, 2002
Messages
43,275
Yes - but of course you would need to change all the column and control names.
 

Users who are viewing this thread

Top Bottom