MS Access Expression - ms-access

I have an Access database I have built from the ground up, I have some queries that I use and work queues. I am trying to narrow down the results of the queries. I have one part that is giving me issues due to how complex the data I am working with is. The one in question I have written the following expression.
Expr1: IIf([Daily Work]![Loan Type]="Renewal"," ",
IIf([Daily Work]![Boarding Date]=Date(),True,False))
This is an expression within a query I am looking to see if Loan Type is Renewal and the Boarding Date is the current date, if both those fields are Renewal and Date respectively then mark the record as true, if not then false. It isn't working for me. What can I can do to make this work?

I'm guessing you're just not getting the results you expect, versus getting an error.
In that case, I would suggest that [Boarding Date] = Date() is most likely the problem. If [Boarding Date] contains a time component, it won't equal Date(). I usually use a date format to compare dates -
i.e.
Format([Boarding Date], "dd mmm yyyy") = Format(Date(), "dd mmm yyyy").
The more explicit you are with dates, the better.

Related

Conditional formatting for current day date

I am just trying to getting my data to do a color fill if the date value equals today.
The data is coming from oracle:
=IIf(Fields!finishDATE.Value = Today(),"Yellow","Transparent")
This will not give me any errors nor will it do the function according to the expression. None of the data with the finish date equaling today highlights.
If today is 8/24/2021 it should look like this:
3/22/2021, 8/24/2021, 2/22/2021
As I'm not sure what format the data will come in from Oracle (I'm a MS SQL person) then this might be overkill but try this
=IIF (Format(Fields!finishDATE.Value, "yyyyMMdd") = Format(Today(), "yyyyMMdd"), "Yellow", Nothing)
All I'm doing here is comparing just the date parts of the date/datetime values.
Below is the output. The first column is the actual date column contents including a time, then for illustration only, the 2nd column shows it formatted to just the date part and the 3rd column show today() with the same format applied.
Finally, I used the keyword Nothing (SSRS almost equivalent of NULL) as this is the correct default value.

Error in Expression used for Control Source in an Access Form

I actually have two questions.
I'm a beginner user of Access, still trying to get a good understanding of the software. I'm trying to create a database for a library (School project) with a borrowing out system. I have two fields in a table called DueDate and DateHired. The DueDate functions on the expression =Now()+28 and the DateHired function on the expression =Now(). Basically making the due date 4 weeks ahead of when the book was hired. My first question is quite simple; if I were to input a record today, would the two DueDate/DateHired fields remain the same date and time by tomorrow? Or would they update to the Now() of tomorrow?
My second question is something regarding an expression. I'm trying to make an Overdue checkbox. The premise is that if Now()>DateDue then the Checkbox will be 'Yes'. My current code in the ControlSource part is this:
=CBool([DateDue]
However, the checkbox simply displays '#Error' and not Yes/No. I'm also concerned that if the answer to the first question was '=Now() stays the same after the record is added and doesn't update' that would also mean the Overdue function would not really work unless you were inputting the record after the due date. Which would make no sense. Any suggestions?
Cheers.
This is relation to your second question. You can ask a separate question for the first part.
=CBool([DateDue]
What you are trying to do here, is convert a Date data type to a Boolean (you're missing the closing parentheses by the way) which is impossible.
What you should be doing is check if the due date is less than today and return the appropriate True/False value.
IIf([DueDate] < Date(), True, False)
Which means:
IIf("Is due date in the past?", "Yes, it's overdue", "No, it's not overdue")
You can read more about the IIf function here.
Indeed as a beginner, make it a habit to use the date functions. Later you can turn to "smarter" methods which, by the way, often aren't that smart.
1.
If you store a date, it remains unchanged in the table. And don't use Now unless you specifically need the hours too:
DateDue = DateAdd("d", 28, DateHired)
or in a query - using the designer:
DateDue: DateAdd("d",28,[DateHired])
or as a ControlSource for a textbox on your form:
=DateAdd("d",28,[DateHired])
2.
You can use DateDiff for this:
Due = DateDiff("d", DateHired, Date) > 28
or in a query - using the designer:
Due: DateDiff("d",[DateHired],Date()) > 28
or as a ControlSource for a textbox on your form:
=DateDiff("d",[DateHired],Date()) > 28
and set the Format property of the textbox to, say, Yes/No or something else meaningful for your users.

MS Access Date Grouping is not working in report

I have created a simple Microsoft Access 2007 app of receiving and paying vouchers, everything is working properly but one thing that my mind doesn't solve.
I have created a report template of "Receiving Amount" where I want report be grouped in respect of receiving date. I have added a field named "Receiving Date" in "Group, Sort and Total" and when I generate it, it doesn't group the content in respect of date.
Adjust your Grouping and Sorting to use the expression:
Fix([Receiving Date])
I found the solution.
The reason of not grouping date wise because Access could not understand the date, like Gustav said, format is just for display but actual value is different and Sergey S said "If the field with date contains time. you won't be able to group the report".
Finally, I had to remove time from the date and keep it clear to Access so it can group my report.
=MonthName(DatePart("m",[receiving date])) & " " & Format$([receiving date],"d"", ""yyyy")
Where receiving date is the field name.

MDX Query in SSRS Shared DataSet giving wrong Datatype

I have a shared dataset for a Mobile Report on SSRS 2016. The dataset sits on a SSAS data source, and has an MDX query to pull from the cube.
The primary key pulled back from the query is a date, and is formatted as such in SSAS; however when I use the dataset in Mobile Report Publisher it doesn't acknowledge it as a date datatype, it thinks it's a string. This means I can't use the dataset as a main series for a time chart, as it doesn't think there's anything formatted as a date.
The below is the section of MDX that I think is causing the issue.
SELECT
{
[Unresolved], [Assigned to Provider], [Unresolved past due date], [Other past due date], [Provider past due date],
[Company past due date], [Provider PDD Daily Change], [Company PDD Daily Change], [Other PDD Daily Change], [Company pre due date], [Company PRDD Daily Change]
} ON COLUMNS,
NONEMPTY(
{
[Date Snapshot].[Date].[Date]
}) ON ROWS
FROM [Source]
WHERE
( FILTER([Date Snapshot].[YQMD].[Date], [Date Snapshot].[YQMD].CURRENTMEMBER.MEMBER_KEY >= '2015-08-15') )
Update: since SQL Server 2016 SP1 the workaround explained below is no longer necessary and dates should be properly recognized without doing anything special:
To try this new functionality out, create a simple MDX query using the Query Designer that includes a date field from your data model. When you consume that shared dataset with Mobile Report Publisher, it will properly recognize the date field from your query without an additional calculated measure being required.
The original text of the answer follows:
The reason as to why this happens is explained in the official Microsoft documentation:
The default return type for Analysis Services queries is a string.
When you build a dataset in Reporting Services Report Builder, the
string type is respected and gets saved to the server.
However, when the JSON table renderer processes the dataset, it reads
the value of the column as a string and renders strings. Then when SQL
Server Mobile Report Publisher fetches the table, it also only sees
strings.
The official workaround is also explained there:
The workaround for this is to add a calculated member when you're
creating a shared dataset in Report Builder.
An example of such a calculated member (taken from here):
cdate(format([Date].[Date].CURRENTMEMBER.MEMBER_VALUE, "yyyy-MM-dd"))
But this workaround (as pointed out by Victor_Rocca in a comment to the official Microsoft documentation) has a big problem:
The downside to this is that it will return all the dates that have
been selected in your query, not just the ones that have a value
associated with it in your cube (essentially removing the NON EMPTY
behavior from the MDX query). When looking at a lot of records across
time, this could significantly impact your report performance.
So I think there's a better workaround which is creating a calculated field in the dataset:
with an expression such as this one (assuming the name of your field is 'Date' and that it returns unique names such as [Date Snapshot].[Date].[Date].&[2010-01-01T00:00:00] and [Date Snapshot].[Date].[Date].&[2010-12-31T00:00:00]:
=CDate(mid(Fields!Date("UniqueName"),33,10))
This way you don't have to manually edit your MDX and NON EMPTY behavior is preserved. This new field gets correctly identified as date datatype in Mobile Report Publisher:
In any case, help is on the way, according to this post based on information obtained at last Pass Summit (October 2016), the following is being developed:
Better support for generated MDX. The current date workaround will no
longer be needed and make everyone’s life easier.
As far as I understand - MDX query language does not contain the data type "Date", hence it will be converted to "String".
IBM support - MDX Data types
Wikipedia - MDX Data types
I had the same problem. You can go around this by creating a Member on the MDX query level using VBA functions:
WITH
MEMBER [Date] AS Cdate([Date Snapshot].[Date].CURRENTMEMBER.Name)
SELECT ...
Your snapshot date needs to have one of the suggested formats. If it does cdate() function should do the trick. SSRS Mobile Publisher will recognize it as a date instead of string.
I've encountered this before and in the tablix cell where I use one of these dates I used the following expression:
=format(cdate(Fields!Calendar_Day.Value),"dd MMM yy")
I ended up wrapping the MDX in a T-SQL query, using OPENQUERY. This is clunky as hell, especially when I needed to pass a parameter, but it allowed me to explicitly convert the result set to whatever datatype I wanted. Urgh.
The only way I managed to get MRP to recognize my date as a real date to filter trough time navigator was adding a calculated measure based on the MemberValue of the Date Dimension.
E.g.:
WITH MEMBER [Measures].[Date2] AS ([_Reference Period].[Date].CurrentMember.MemberValue)
And after that, adding the field [Measures].[Date2] to the measures of the query:
SELECT NON EMPTY { [Measures].[Date2] } ON COLUMNS, NON EMPTY { ([_ReferencePeriod].[Date].[Date].ALLMEMBERS * [Companies].[Company].[Company].ALLMEMBERS * [Contract].[Type].[Type].ALLMEMBERS * [Employee].[Gender].[Gender].ALLMEMBERS * [Situation Type].[Situation Type].[Situation Type].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_VALUE, MEMBER_UNIQUE_NAME ON ROWS FROM [SOURCE] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

Classic ASP, DATE difference between IIS6 and IIS8

I am helping to migrate a classic asp website (front end) and ms access database (back end) from a Windows 2003 IIS6 server to a Windows 2012 IIS 8.5 server. I am having a problem with this query in particular;
sqlquery1 = "Select RentalNum, CarID, RentalStatus, StartDate, EndDate from table where CDate(EndDate) <= CDate('"&Date()&"') order by CDate(EndDate) desc"
On the existing system all is ok. On the new system the returned results are not <= "todays date". The results show some dates before today and some after. The database date fields are just "text" (I didn't set it up) and whilst my initial thoughts were to change the schema to proper dates, I would like to understand the problem, particularly as there are many of parts of the system using similar queries using date() and CDate. Are there underlying dates differences between IIS servers? I have looked at browser locality and all is ok there.
Any pointers?
Examine this expression used in your query:
CDate('"&Date()&"')
The Date() function returns the system date as a Date/Time value. But then that expression adds quotes before and after the Date/Time value, which transforms it to a string value. And then CDate() takes that string and transforms it back to a Date/Time value again.
Hopefully that description convinces you those manipulations are at best wasted effort. However if the two servers have different date format settings, the dates resulting from that full CDate() expression could be different.
I'm not positive that is the source of your problem, but you can easily eliminate the possibility. The Access db engine supports the Date() function, so you can use it directly without first transforming it to a string and then back into a Date/Time value.
sqlquery1 = "Select RentalNum, CarID, RentalStatus, StartDate, EndDate " & _
"from [table] where CDate(EndDate) <= Date() order by CDate(EndDate) desc"
If that change does not solve the problem, next examine those EndDate text values and make sure they're interpreted as the date you expect:
SELECT EndDate, CDate(EndDate) AS EndDate_as_date
FROM [table];
You mentioned your "initial thoughts were to change the schema to proper dates". I think that is the best way to go because developement based on dates as Date/Time is saner than with dates as strings.