Recognition of a date as a date in Access Forms filtering - ms-access

I have an Access data table with the Field "RequiredUntil", which is from the type "Date/Time", and several other columns, and a form, in which I show that table, and where I usually use right mouse click to filter for what I want. The text box for "RequiredUntil" is formatted as "Short Date".
Part of the form:
When I now do a right click on the field "RequiredUntil" in that form, Access properly recognizes that as a date, and offers me several date filters, i.e. Today, "This week", Past,... So I don't use any SQL there, all is done by Access!
When I select "Today" (or Yesterday or Tomorrow), I get a "Data type mismatch in criteria expression" error.
When I select "This week" (or any other time period), the filter is properly set - but as soon as I filter the next column, I get a
Syntax Error in Query expression '((Year([DataTable].[RequiredUntil])=Year(Date())) AND
(DatePart("ww";[DataTable].[RequiredUntil];0)=DatePart("ww",Date(),0))'.
In that case, the date filter is revoked, and only the second filter is applied.
So, I don't do any SQL, RequiredUntil is of the type Date/Time, the text field in the Form is Date/Time, Access recognizes it as Date - what am I missing?

I'm pretty sure, the issue is caused by Null values in your date field.
If removed, you can set the filter, which will reveal as:
(DateSerial(Year([DataTable].[RequiredUntil]), Month([DataTable].[RequiredUntil]), Day([DataTable].[RequiredUntil])) = Date()+1)
which, obviously, will fail, as DateSerial doesn't accept Null values.

Related

Date time parameter in SSRS

I have a report which requires user to type the start date and also allow them to choose from calendar. I was wondering if its possible to enter the date as a string. Right now, I have a text field with calendar and I would like the user to enter date[06302015] instead of [06/30/2015]
can we omit the dashes and still have the report format it to date?
The type of a parameter can be changed from Parameter Properties like below.
This will remove the Calendar and it will be only a Text box.
Change your parameter type to "Text".
Add a second "Hidden" parameter (as Date/Time data Type) that takes the LAST_DATE_EDITED as an input into the 2nd parameter's default value using the expression: =DateValue(Mid(Parameters!LAST_DATE_EDITED.Value,1,2) & "/" & Mid(Parameters!LAST_DATE_EDITED.Value,3,2) & "/" & Mid(Parameters!LAST_DATE_EDITED.Value,5,4))
(Not tested, but it should be close)
Then use the 2nd parameter in your report instead of LAST_DATE_EDITED.
If the user inputs an incorrectly formatted string of numbers, uses text, etc., SSRS will throw an exception.
IMO, this isn't the most elegant solution and it demands user input that is prone to errors. Not what I would implement (I would have the users use the built in DateTime picker and train them to use valid separators such as periods, slashes or dashes or just use the calendar control).

MS Access, Use Expression Builder to Compare Field in One Table to DLookup in Another Table

I'm trying to make a MS Access report, where I use a text box to display a field value, then have another text box indicating if the first value is higher or lower than an entry in a separate table.
The report has a record source of "Table 1", and a textbox named "txt_Value1" which displays the number in Field: "Value1". I have a second table, "Customer_Criteria" which has a field "PassValue" that I want to compare against. My expression builder statement is:
IIf([txt_Value1]<(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'")),"TRUE","FALSE")
This statement always returns false, regardless of what the correct logical result is.
I've tested it, writing:
IIf(1<(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'")),"TRUE","FALSE")
And I get the correct results. Also, if I write:
IIf([txt_Value1]< 1,"TRUE","FALSE")
I get the correct results. What am I missing to compare the textbox value vs. the Dlookup?
As I understand, both fields are numeric. Access may consider those fields as text, so for correct comparing use type conversion.
Try this:
IIf(CLng(Nz([txt_Value1],0))< _
CLng(Nz(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'"),0)), _
"TRUE","FALSE")
Nz required if fields may contain NULL values, in this case type conversion function will return error.

MSAccess Change Date Value Before Validation

In a grid I have a date/time field where I would like the user to be able to type in short-hand formats for dates and times. For example, if they type in "435p" and then focus off of the cell they get the message "The value you entered isn't valid for this field.". Instead, I want to trap a pre-validationevent and change it to "4:35pm" for them.
What event can I use?
I've tried:
LostFocus & BeforeUpdate: too late (validation fires before event)
Dirty & OnChange: too early (they haven't left the cell yet)
Or is there a way to turn off the native validation rule that is checking for date formats?
You could use an additional text field without formatting (or with your very own format). Then show this instead of the datetime-field and update the date-time field with your code.
Not very pretty, but if you always format the input to a proper time string on before-update and never access this field (but rather the real date-time field) you should be ok. You could even name the field Helper_DateTime or somesuch, so you are never tempted to access the field from anywhere else ;)

Converting user-typed dates from date picker

I have a report that uses date params (so have to be datetime in SSRS, which sucks to start with). When the user enters a date such as "5/1" it creates a DateTimeOffset data type and I can't find anyway to cast it to anything else, format it, or concatenate in a text box. I tried casting to a date to a string, etc. All I get is:
Conversion from type 'DateTimeOffset' to type 'String' is not valid. ('String' is replaced by anything I try to cast it to)
Surely there must be a way to have a text box show "From 5/1/2013 to 5/31/2013" when the user types "5/1" and "5/31" in the date field? Does Microsoft really think computer-literate people want to pick up the mouse to use their date picker instead of using tab?
Try the following expression:
="From " & Format(Parameters!Param1.Value.DateTime, "M/d/yyyy") & " to ..... etc"
To test this expression I've created a fresh report, added a DateTime parameter, and entered "5/1" in the textbox, hit enter. The report comes up with the following textbox:
From 1/5/2013 to ..... etc
For my locale, this is correct, because when entering DateTime values days are assumed to come before months. When the report is viewed the textbox will also update and show:
5-1-2013 0:00:00 +01:00
From this you should be able to extrapolate and use it for a second parameter as well, extending the expression to show the exact string you need in your report.
The Parameters!Param1.Value.DateTime helped when the user omits the year, but it broke down when the user decides to include the year. I couldn't get it to work under both conditions.
Try this.
Include the date parameter value as a field in your resultset. Your SQL might look like:
SELECT field1, field2, Convert(date, #FromDate) [FromDate_param] FROM table
Then you can create an expression in SSRS like:
="From " & Format(First(Fields!FromDate_param.Value), "M/d/yy")

Problems Creating Date Range with Date Picker for an Access Report

I have searched everywhere for this and tried different criteria but for whatever reason the form which has a control box set to open a report which is based upon a query will not pull the data within the date range. Instead keep getting enter parameter value dialogue box.
The criteria in the query is stated as Between [Forms]![Form1].[StartDt] And [Forms]![Form1].[EndDt]
The form has two date inputs StartDt and EndDt and is pointed to open the report. Without the above criteria in the query the form opens the report and produces all the dates. So at least it allows me to enter dates and is connected to the query and report but without the criteria fails to isolate data within the required range.
When I place into the query containing the criteria (as above) under the appointment date field all im getting are two parameter value dialogue boxes one after the other displaying Forms!Form1.StartDt and the second, Forms!Form1.EndDt.
Apologies for being long winded but am desperate to solve this issue am new to access.
Thanks to everyone for any input.
Iain
It seems you have an error in your names. One of the easiest ways to check form names is to use the immediate window. Type ctrl+G and you will end up in the code window with the cursor in the Immediate window. With the form open and a date filled in, type or paste
?forms!form1!StartDt
Into the immediate window and hit return. If you get an error, it means that you have a name wrong somewhere along the line, either your form is not called Form1, and form names can be a little complicated, or your control is not called StartDt. So this is where the version of Access comes in. In Access 2010, if you type Forms! on the criteria line of a query and wait a second, it will give you a list of forms. Pick your form from the list and type ! after the name, Access will come back with a list of controls. Pick your control. You should now have the right form and control name.