Microsoft Access - Between two date range with 1 user input - sql

I want my query to ask the user for 1 date and use that same date to create a between date condition in my query. I manage to get the date to be used in the query, but I can't seem to be able to add +6 days to it.
Field
dateRecorded
Condition
Between [Enter start date(mm/dd/yyyy)(Monday)] And [dateRecorded]+6
I don't want the user to enter 2 dates to filter by.

If you enter more than one parameter with the same request string it will only ask once and use the same input:
Between [Enter an integer] And [Enter an integer]+6
However I don't think this will work with dates; I know it does with integers etc.
I also agree with comments in question that it is better to use a form for such things to get more control; validation of correct dates such as ensuring the date entered is a Monday.

Related

I need to convert total date to month only

I set up a google forms form for my work where my employees pass information and this information is recorded in a spreadsheet. The information, when recorded, automatically inserts a date and time in the first column of form responses. However, when I enter the code = month (a1), it always returns the answer "1" or "January" and this information does not match the date entered in the column. How do I fix this?
If you are entering '=month(a1)' for every row, then you are always taking the month of the top left cell in the sheet. You would need to adjust the row number for the row you are in.
You could use something like '=month(now())' to ensure you are always getting the month of the current date.

Trouble with an Access Query searching within a date range

I have a query that searches saved records and creates a report based on the record(s). Some of the fields are searchable either independently or in association with other parts of the saved record (e.g., one could search the ID, location, and/or whether or not police were notified). However, I run into problems when searching by date.
I have fields for the user to input Start Date and End Date of their desired date range. When ONE or NEITHER field are filled, the search pulls up all records AFTER the Start Date, BEFORE the end date, or ALL the records. When BOTH fields are filled, the search pulls up a record where all fields are blank (which does not exist in the table).
Each searchable field uses the same criteria in the Query:
Like Nz([field that you're searching],"*")
But the date range uses a modified version (sorry if it's SUPER clunky):
Like Nz(([Data_Input_Table].[Day_Current])>=[Forms]![Search_Form]![Start_Date_Lookup_text] And ([Data_Input_Table].[Day_Current])<=[Forms]![Search_Form]![End_Date_Lookup_text],"*")
Ideally, I'd like the user to search by NEITHER, ONE, or BOTH Start Date and End Date.
Please help!
You can't use Like on dates. Try this:
[Data_Input_Table].[Day_Current] >= Nz([Forms]![Search_Form]![Start_Date_Lookup_text], [Data_Input_Table].[Day_Current]) And [Data_Input_Table].[Day_Current] <= Nz([Forms]![Search_Form]![End_Date_Lookup_text], [Data_Input_Table].[Day_Current])

SSRS parameters based on selection?

I hope someone could help with this?
I am building a report based on a stored procedure that has the following clause in it
where accountingperiod = #Accountingperiod or createddate between #Startdate and #Enddate
#Accountingperiod will be in the following Format 'Oct 2017'
#Start and #Enddates are just generic date formats.
I basically want my report to load and have the option to select whether the user wants to filter the report using the #Accountingperiod parameter or the date parameter (as both bring back entirely different data). Once the user has selected which one is to be used, the parameters (for example, #accountingperiod) will be available for selection.
How can this be achieved? Apologies if this is a silly question, I am quite new to SSRS!
Thank you
There are several ways to do this. The simplest would be to do it in the Stored Procedure and just test if Accounting Period has been set, if so use that, if not use the date range but that might not be intuitive for the user as they could select an accounting period AND a date range without realising that the date range would be ignored.
The most elegant solution would be to set the start and end dates based on the accounting period and have another entry in your accounting period list called 'Date Range' or 'Any' etc.
This assumes you can lookup or calculate the start and end dates for each accounting period. For the sake of simpicity in this example we'll assume that you have a table (say myAccPeriodTable) with the periods and date ranges in, something like this..
AccPeriodID AccPeriod StartDate EndDate
1 2017-Q1 2017-01-01 2017-03-31
2 2017=Q2 2017-04-01 2017-06-30
3 2017=Q3 2017-07-01 2017-09-30
etc...
Create a dataset (lets call it dsAccPeriods) with the following query
SELECT AccPeriodID, AccPeriod FROM myAccPeriodTable
UNION SELECT -1, 'Use Date range'
ORDER BY StartDate
You Accounting period Parameter (assume this is called #AccPeriodID) Available Values would be from a query and point to dsAccPeriods
The Value would be the AccPeriodID field and the Label field would be AccPeriod
Now create two more datasets say, dsDefaultStartDate and dsDefaultEndDate with the following queries respectively.
SELECT ISNULL(StartDate, 1999-01-01) AS StartDate From myAccPeriodTable WHERE AccPeriodID = #AccPeriodID
and
SELECT ISNULL(EndDate, 2020-12-31) AS EndDate From myAccPeriodTable WHERE AccPeriodID = #AccPeriodID
For your 'StartDate' parameter (assume its called #StartDate) the Default Value would simply point to the dsDefaultStartDate dataset and do the same with #EndDate pointing that to dsDefaultEndDate.
Now when the user selects a start date, the two data parameters should be populated with hte correct dates so your Stored Proc can simply filter based on the #StartDate and #EndDate parameters. If the user chooses the use Date Range option then the default dates will be set to whatever dates you specified in the dsDefaultStartDate and dsDefaultEndDate datasets.
Of course there is a chance that the user selects a real accounting period and then changes the date ranges. There are things you can do to avoid this but one step at a time !
I've written this answer without testing anything so there could be some mistakes but hopefully it will point you in hte right direction. If you have any issues leave a comment.

Between Date Range in a QUERY Not Working

I have a Date for Example a Departure Date of a Flight for 15/01/2014 and I want to create a query that remind me 30 days before departure.
I tried the following in the CRITERIA but none of them work
DateAdd("m",1,[DepartureDate])>=Date()
Between DateAdd("m",1,[DepartureDate]) And [DepartureDate]
IIF(DateAdd("m",1,[DepartureDate]) < Date(), True, False)
You posted this quite a while ago, so I presume you managed to solve it. But if not, here is an answer for you.
There are two ways to do this.
Option One
The easiest way is to enter this in the CRITERIA of your DepartureDate field:
=Date()+30
Option Two
Alternatively, you could create a new column in your query that you filter on. To do this in your query, enter this in the FIELD row for a new column:
30DaysAway: IIf([DepartureDate]-30=Date(),"yes","no")
This will give you a new column in the query titled "30DaysAway". In that column it will say "yes" if the departure date is 30 days away from today, and "no" for all other dates.
Then in the CRITERIA for that query field, enter "yes".
Either of these options will filter the list of results and only show you entries with a departure date that is 30 days away.

record count based on current date (Today's date)

I have a form in which I enter a record and I have a field that automatically updates with the current date. I would like to add a subform that tells me how many records have been entered "today" based on current date (today's date). I would like it to keep a running total. I am new to asking questions in this format and appreciate any help and understanding.
For Access:
SELECT COUNT(*) FROM ... WHERE add_date BETWEEN DATE() AND DATE()+1;
as suggested by David W. Fenton in the comments.