Date time parameter in SSRS - reporting-services

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).

Related

Recognition of a date as a date in Access Forms filtering

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.

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")

Microsoft Access 2007, Macro issue, form and database with phone numbers

I'm trying to write a little form which accepts some user input, and on the basis of some logic displays one of two possible other forms. Everything is working fine if I use simple, unformatted data, but I hit a problem if the data in question has an input mask of a phone number. Presumably there's a trick here to ignore formatting characters or some such?
The actual logic looks for records in a particular table whose values match the data entered. Something like this cut down example:
A form, which is not associated with any specific table, containing one data entry field, called FormFieldY, and a button whose onClick invokes a Macro whose condition looks for matching data in a table.
DCount("*","TableX","[MyColumn] = [FormFieldY] " ) > 0
Now, if I MyColumn in the table has simple text or numeric values this works just fine. However if I apply a Telephone number input mask to that column, I never get a match. I have tried applying an input mask to my form field, or typing literally into the form field a fully formatted number
(1234) 56789012
neither gives a match. However if instead I hack the macro and enter a suitable hard-coded formatted valueL
DCount("*","TableX","[MyColumn] = '(1234) 56789012'" ) > 0
It works just fine.
I think you may have two issues going on. The first is that your format property displays the parentheses when a user types in a phone number, but those parentheses are not included in the value of FormFieldY --- they are display-only.
You can verify the value of FormFieldY by assigning this code to its After Update event:
Private Sub FormFieldY_AfterUpdate()
MsgBox Me.FormFieldY
End Sub
If you want the parentheses stored as part of FormFieldY's value, perhaps you would get more joy by using an input mask rather than a format. With Access 2003, I used this as my text box control's input mask:
!\(999") "000\-0000;0;_
But it's probably easiest to use the Input Mask Wizard (click the button with 3 dots, which is just to the right of the Input Mask line on your control's property sheet). Choose phone number on the first wizard page. On the Wizard page which asks "How do you want to store the data?", select the "With the symbols in the mask" radio button.
Comment from djna: That was the solution, the expression change below seems not to be needed
The other issue is your DCount expression:
DCount("*","TableX","[MyColumn] = [FormFieldY] " ) > 0
I think you should use the value of FormFieldY rather than the name of the control. That may not be clear, so here's what I mean:
DCount("*","TableX","[MyColumn] = '" & Me.FormFieldY & "'" ) > 0

Data Type Error when added Input Mask on Date Time Field

i have a date/time field called MyDate. Originally, its format is mm/dd/yyyy and there is no input mask. The Date Picker is also set. I then added input mask using Short date , changed the default input maks to (99-99-0000;;_) and change the format to mm-dd-yyyy. However, when i switch to DataSheet view , all my dates are changed from mm/dd/yyyy to mm-dd-yyyy (which is the correct behaviour right? ) and when I tried to enter a new date or modify existing date, it says "The value you entered does not match Date/Time data type in this column". Plus, the DatePicker is missing. How can I resolve this. thank you
The date time picker is not available if an input mask is applied to a field: http://office.microsoft.com/en-us/access-help/add-and-customize-date-and-time-formats-HA010078108.aspx#_Toc272229486
Regarding the error, have you considered using your regional settings in the control panel, which sets the defaukt date display for all (most?) applications?
Dates in Access are stored as numbers, so you can format them however you like, but I suspect the input mask may need to match the regional settings, although I am not certain.