Access 2010 calculated field reference from a textbox - ms-access

I am working on access I am stuck in a point.please help
i have a calculated field :
Sum(IIf(Format([Ref_Date],"yyyymm")
Between
Format(DateSerial(Year(Date()),1,1),"yyyymm")
And
Format(Date(),"yyyymm"),1,0))
it is calculating automatically but I have a report filter tool where I will select the date, now I need to pass that date range(that is: user date range) into this function so that it should work for any dates.
How can I achieve that?

You can create a function like this in VBA that will return true if the date is in the required range and you can then use that result to perform any other calculation.
Function InDateRange(RefDate As Date, StartDate As Date, EndDate As Date) As Boolean
If (RefDate >= StartDate) And (RefDate <= EndDate) Then InDateRange = True
End Function
You can use the function in the control source of a text box;
=IIF(InDateRange([txtRef],[txtStart],[txtEnd]),1,0)
where txtRef, txtStart and txtEnd are text boxes with the date values in.

Related

Disable the "Weekend" on SSRS Date Type Parameter

I have a report and the report has parameter (#date) for user to pick a date.
Currently, my parameter (#date) use Parameter Properties > Default Values > =Today() (For set today date as default paramter).
But I also want the parameter can disable the weekend days.
So the user only can select the weekday.
How can i do it ? Please help.
You cannot disable weekends on the date picker. If the user selects a weekend date and that will not result in error. May I suggest using visibility to hide your tables/matrices based on the date they select?
In your table(s) properties, go to the table visibility option and use this expression:
=IIF(weekday(Parameters!YourParameterName.Value) = 1, TRUE,IIF(weekday(Parameters!YourParameterName.Value) = 7, TRUE, FALSE))
Add a textbox after your table(s), include an "error message" in the textbox to display for users if they select a weekend date. Go to the textbox property, visibility option and use this expression:
=IIF(weekday(Parameters!YourParameterName.Value) = 1, FALSE, IIF(weekday(Parameters!YourParameterName.Value) = 7, FALSE, TRUE))
I'm using nested IIF function in here but you can use SWITCH if desired.
The result is when a weekend date is selected, your textbox will be displayed with your message. Otherwise your table(s) will show.
If you don't mind losing the functionality of the date picker you could set up the #date parameter to use the following query, currently set to +/- 60 days from current date, which you could amend to suit your requirements:
;with dates ([startDate]) as (
Select convert(date,DateAdd("d",-60,(getdate()))) as [startDate]
union all
Select dateadd(day, 1, [startDate])
from dates
where [startDate] <= DateAdd("d",60,(getdate())))
select [startDate]
from dates
where datepart(dw,[startDate]) in (2,3,4,5,6)
option (maxrecursion 32767)

Date to clubbed with pre-define time at SSRS

At SSRS, one of my reports have date range as parameter - From Date (#FD) and To Date (#TD), these two parameters pass at query for the report to generate
At SSRS the parameter is of date/time type, I'm looking for a solution whereby when user select a date range it should include the time factor as below
if the user has selected say, FD 01/09/2018 and TD 30/09/2018 from report date picker
then I want the parameter to pass as 2018-09-01 00:00:00.000 and 2018-09-30 23:59:59.000 to the query. This 00:00:00.000 and 23:59:59.000 as a fixed range suffix to date.
How to achieve it?
I was trying combinations, this one i found working sort of.. got some clues for many forum
declare #FFD datetime2
declare #TTD datetime2
set #FFD = cast ('2018-09-01' as DATE)
set #TTD = DATEADD(s, -1, DATEADD(S, 86400, '2018-09-30'))
print #FFD
print #TTD

Access SQL Date Format Inconsistent

I currently have a table in my database keeping track of a start date and end date for a service. I need to compare a date entered by the user to see if it is between the start and end dates. My issue right now is that in the table, access stores that start date as DD/MM/YYYY, the textbox in my form that the user puts their date in is formated as DD/MM/YYYY. However, once I hit VBA and run an SQL query, it reads the date as MM/DD/YYYY.
My query is:
SELECT * FROM table WHERE #09/01/2018# BETWEEN startDate AND endDate
My test entry is:
table:
startDate endDate service
08/01/2018 02/02/2018 ABC
This should return this entry, however as it reads it as MM/DD/YYYY it does not. If I enter #13/01/2018# it returns the entry as it detects that 13 is the date and cannot be a month. How could I correct this so that it takes 09/01/2018 and returns the entry as well?
If this is an VBA query then your observations are correct. In the Query designer these will work as expected.
Review Allen Browne's excellent explanation here; http://allenbrowne.com/ser-36.html
with solutions as well.
Your query should use either the "reverse" US sequence or the ISO sequence:
SELECT * FROM table WHERE #2018/01/09# BETWEEN startDate AND endDate
or, if you build it from code:
SearchDate = SomeDateValue
SQL = "SELECT * FROM table WHERE #" & Format(SearchDate, "yyyy\/mm\/dd") & "# BETWEEN startDate AND endDate"
or, if you always search for today:
SQL = "SELECT * FROM table WHERE Date() BETWEEN startDate AND endDate"

Crystal Reports : Bad Date format string error

I am a newbie to crystal reports, I have a crystal report for which I have a data source from which I am using some fields on to the report.
Crsytal Report Name : InventoryReport
Data Source : I am giving Stored Procedure -- GetInventoryData
Fields : ItemID, ShippedDate, ItemName
I have to get all items which are shipped in between FromData and ToDate of ShippedDate, so I am using formula {GetInventoryData;1.ShippedDate} in {?FromDate} to {?ToDate}
dataType of Shipped Date is String and I have to convert to Date as it needs to be compared but I am having issues in that...
ShippedDate value will be : 2011-04-19 16:02:14.0000000
I have to convert at crystal reports side only..
Please help me how can I cast it to date
actually even better don't use that formula .... in selection formula using the date range explained above
date(split({GetInventoryData;1.ShippedDate}," ")[1]) in {?daterange}
If you are using string, you may do a simple less-than or greater than like:
...where ShippedDate >= '2011-04-19 00:00:00' and ShippedDate <= '2011-04-19 23:59:59'
this is like:
...where ShippedDate >= '<from-date> 00:00:00' and ShippedDate <= '<to-date> 23:59:59'
This would work and you'll not have to cast to a date.
You may also use as (If it works for you):
...where ShippedDate >= '<from-date>' and ShippedDate <= '<to-date>'
one way ... create a formula called cvtDate
date(
tonumber(split({GetInventoryData;1.ShippedDate},"-")[1])
,
tonumber(split({GetInventoryData;1.ShippedDate},"-")[2])
,
tonumber(split({GetInventoryData;1.ShippedDate},"-")[3])
)
then instead of creating two date parameters.. create only one called daterange that allows range values under values options
Then selection formula would be
{#cvtDate} in {?daterange}

Printing parameters in an Access parameter query

I am developing an Access report based on a query that has a date range as a parameter,
like this
Between [Enter Start Date (mm/dd/yyyy)] And [Enter End Date (mm/dd/yyyy)]
How do I include the values entered for the start date and the end date in the report?
Thanks in advance.
GRB
You have to select the input values as columns in the query, using the exact names like in the Where clause.
Your query will probably look something like this:
select
Column1,
Column2,
DateColumn
from
MyTable
where
DateColumn between [Enter Start Date (mm/dd/yyyy)]
and [Enter End Date (mm/dd/yyyy)]
To include the input values in the query, you have to change the query like this:
select
Column1,
Column2,
DateColumn,
[Enter Start Date (mm/dd/yyyy)] as StartDate,
[Enter End Date (mm/dd/yyyy)] as EndDate
from
MyTable
where
DateColumn between [Enter Start Date (mm/dd/yyyy)]
and [Enter End Date (mm/dd/yyyy)]
You can use any alias you want for the input values (I used StartDate and EndDate), as long as the actual column names ([Enter Start Date (mm/dd/yyyy)] and [Enter End Date (mm/dd/yyyy)]) are exactly the same.
Of course this means that the query will contain the input values in every row, but you don't need to show them in every row in the report.
Just put the fields bound to StartDate and EndDate in the header or in the footer of the report, and the values will show up in the report only once.
DoCmd.OpenReport has some additional parameters for the filter, a where clause and most importantly OpenArgs. During the report load event you can capture these arguments to customize the Data Source for your report (EG: The range to select from) and set the value of Labels on the report to the input provided prior to opening up the report.
http://msdn.microsoft.com/en-us/library/bb238032%28v=office.12%29.aspx provides an overfiew of this functionality.
I envision a form where the user selects a date range from and hits OK. The report is called to open through the button click event and the date range (once validated on that end) is passed in through OpenArgs.
Also, you could just use the overloads to set the date range in the where/filter parameters and pass the full date range into OpenArgs such as "January 1 - January 31" and assign it to the Label.Text for the label on the report