SSRS 2016 export to excel removes new lines - reporting-services

devs.
I have report created in SSRS 2016 which use Tablix.
In my cell "TestBoxTEST" I added expression
=Fields!MyField1.Value+chr(10) + chr(13) + CType(Fields!GUID.Value, GUID).ToString
It looks perfect on ReportViewer, Word, Pdf even in PowerPoint...
But when I export the report to excel row is in the single line.
So far I have tried:
1) chr(13)
2) chr(10)
3) vbcrlf
4) "" - with placeholder (as html)
Any ideas?

Try using Environment.NewLine in your expression:
= Fields!MyField1.Value & Environment.NewLine & CType(Fields!GUID.Value, GUID).ToString
In my example I use a two line string

Related

How to set the previous "MONTH/YEAR" based on the TODAY() value in an SSRS expression

I am working in VS2017 and I am trying to define in my textbox expression the PREVIOUS "MONTH/YEAR" in SSRS. Today's date is 2021-01-06 and I'm trying in my SSRS expression to configure that and I'm not having any success. Any help/direction would be appreciated, thanks.
Here is the code that I've tried in my SSRS expression:
="Agent Report " & vbcrlf & "for: " & MonthName(Month(DateAdd("M",-1,Today.Date))) & " - " &
IIF(Today.Month = 1, (Year(DateAdd("Y",-1,Today.Date))), (Year(DateAdd("Y",0,Today.Date))))
When I execute the code above I'm getting this error in VS2017:
Severity Code Description Project File Line Suppression State
Warning [rsRuntimeErrorInExpression] The Value expression for the
textrun 'Textbox1.Paragraphs[0].TextRuns[0]' contains an error:
Argument 'DateValue' cannot be converted to type
'Date'. C:\Users\msavoy\source\repos\SSRS Reports_Updated\SSRS
Reports_Updated\Agents Using a Rater Report.rdl 0
I'm not sure where your error comes from, the expression evaluated without an error when I tried it. It did return, what I think, is the wrong answer though.
I simplified it to this...
="Agent Report " & vbcrlf & "for: "
& MonthName(Month(DateAdd("M" ,-1,Today.Date)))
& " - "
& IIF(Today.Month = 1, Today.Year - 1, Today.Year)
This returned
Agent Report
for: December 2020

Multiple filter clauses for query and subsequent report from unbound form controls, button activated

Been a while since I used Access and now stuck with a reporting problem.
I have a form, with various unbound controls. There a start date, end date and three levels of business/asset/location in combo boxes.
I can get my query and report to work for each of these as individual 'where' clauses when clicking on a button. That's fine.
However I would like to know what code I need to use when clicking a button so I can combine one or more of the above controls to filter the report i.e. my date range + Business, or date + Business + Asset etc.
I have been trawling the internet and testing different variations but seem to have gone through the error book so far.
My latest effort (on click) as one long string gives me a data mismatch error. If I remove the BU/Asset/Facility parts then my date range code does work. However, it's the combination of these I want to filter by.
DoCmd.OpenReport ReportName:="rptVerification_Results", View:=acViewPreview, WhereCondition:="[Date Entered] Between #" & Me.StartDate & "# AND #" Me.EndDate & "#""" And "BU = " & Me.cboBusiness & "" And "Asset = " & Me.cboAsset & "" And "Facility = " & Me.cboFacility & ""
As you can probably tell I'm winging it and need some direction please.
Thanks
It can be tricky to get the combination of quoted strings and form fields right, as you need to be aware of which quotes are being used to concatenate the WhereCondition string together and which quotes are being presented to the query engine. You also need to know which fields are text and which are numeric, because text fields need to be enclosed in quotes in the resulting string, while numerics don't. I'm assuming below that cboBusiness, cboAsset and cboFacility are all text.
I suggest you create a separate variable to store your WhereCondition in:
Dim myWhereCondition As String
myWhereCondition = "[Date Entered] BETWEEN #" & Me.StartDate & "# AND #" & Me.EndDate
& "# AND BU = '" & Me.cboBusiness
& "' AND Asset = '" & Me.cboAsset
& "' AND Facility = '" & Me.cboFacility & "'"
DoCmd.OpenReport ...
WhereCondition:=myWhereCondition
You can then create a debug breakpoint on the "DoCmd" statement and check the value of "myWhereCondition" in the Immediate window, to make sure it is formed correctly, before DoCmd runs.
IIRC, you can use apostrophes/single quotes as an alternative to double quotes in MS Access, as I've done above. If this is not the case, then each of the single quotes above would need to be converted to "double double quotes" (because a double quote on its own would terminate the string).
The somewhat messier "double quotes everywhere" version of the WhereCondition would be:
myWhereCondition = "[Date Entered] BETWEEN #" & Me.StartDate & "# AND #" & Me.EndDate
& "# AND BU = """ & Me.cboBusiness
& """ AND Asset = """ & Me.cboAsset
& """ AND Facility = """ & Me.cboFacility & """"
Note that if any of the cbo fields are numeric, you need to remove the corresponding single (or double double) quotes from each side of that field.
Try this WhereCondition:
Dim WhereCondition As String
' First, adjust the WhereCondition:
WhereCondition = "([Date Entered] Between #" & Format(Me!StartDate.Value, "yyyy\/mm\/dd") & "# And #" & Format(Me!EndDate.Value, "yyyy\/mm\/dd") & "#) And BU = '" & Me.cboBusiness & "' And Asset = " & Me.cboAsset & " And Facility = " & Me.cboFacility & ""
' Then, open report:
DoCmd.OpenReport ReportName:="rptVerification_Results", View:=acViewPreview, WhereCondition:=WhereCondition

Exporting to CSV dropping off text

I am attempting to export out a concatenated note from a table in a database I'm given and export it out into a CSV file. The below code works getting it to be seen in the Datasheet view. However whenever I export the file to a CSV the Note column is cut off at "Actual Note:" and CnNote_1.CnNote_1_Actual_Notes is not displayed. I'm not sure what could cause this and would like help figuring it out.
One potential thing to consider is that CnNote_1.CnNote_1_Actual_Notes is a long text field while all other fields, except the two date fields, are short text fields. I don't know if that's causing it though.
My only other guess is there a hidden character in the beginning of the Actual Note.
I'd greatly appreciate any insight as to why it might be dropping.
SELECT CnBio.CnBio_Import_ID,
CnBio.CnBio_First_Name,
CnBio.CnBio_Last_Name,
CnBio.CnBio_Org_Name,
CnNote_1.CnNote_1_Type AS [Note Type],
Format(CnNote_1.[CnNote_1_Date], 'yyyy-mm-dd') AS [Date],
Format(CnNote_1.[CnNote_1_DateAdded], 'yyyy-mm-dd') AS [Original Date],
IIf(CnNote_1.CnNote_1_Title <> '', "Title: " & CnNote_1.CnNote_1_Title & " ") & IIf(CnNote_1.CnNote_1_Description <> '', "Description: " & CnNote_1.CnNote_1_Description & " ") & IIf(CnNote_1.CnNote_1_Actual_Notes <> '', "Actual Note: " & replace(replace(CnNote_1.CnNote_1_Actual_Notes, Chr(13), " "), Chr(10), " ")) AS Notes
FROM (Cn LEFT JOIN CnBio ON Cn.CnBio_LINK = CnBio.CnBio_LINK) LEFT JOIN CnNote_1 ON Cn.CnNote_1_LINK = CnNote_1.CnNote_1_LINK
For more information I'm exporting via MS Access's export using the Text File export. It also occures when exporting out using the Excel unless I select "Export out with formatting and layout."
I am not sure if that is the only problem but you are using IIF wrong.
Instead of
IIf(CnNote_1.CnNote_1_Title <> '', "Title: " & CnNote_1.CnNote_1_Title & " ")
Use
IIf(CnNote_1.CnNote_1_Title <> '', "Title: " & CnNote_1.CnNote_1_Title & " ", "")
All of your IIFs are similarly flawed.

Is is possible to add in more information retrieved after a Lookupset call in SSRS?

I have 2 datasets from which I populate my report, ActiveProjects (primary dataset) & ActiveTasks. I use the expression:
=Join(lookUpset(Fields!Title.Value, Fields!Related_Project.Value, "" & Fields!Title.Value & "", "TeamTasks"), "<br> <br>")
This works great for retrieving each task grouped with its related project and it also includes a dynamic URL to the respective tasks.
My question is: Is it possible to include additional pieces of information (such as TargetDate - which is in the ActiveTasks Dataset) to be placed alongside the Task in the same Column & Row (Otherwise it wont remain aligned as the Task list goes on, since they are of varying length, while the date is not) ?
Ideally, it would return something like this:
Project Title Task Title
_______________|_________________
Project A | Task a 12/12/16
| Task b 02/12/16
| Task c 28/11/16
Project B | Task a 22/11/16
|
Thanks in advance and sorry if this has been addressed before!
Try:
=Join(
lookUpset(
Fields!Title.Value, Fields!Related_Project.Value,
"<a href = " & Chr(34) & "https://example" & Fields!ID.Value & Chr(34) &
">" & Fields!Title.Value & "</a>" & " " & Fields!TargetDate.Value , "TeamTasks"
),
"<br> <br>"
)
Also you may want to format your date, so you can use FORMAT(Fields!TargetDate.Value,"dd/MM/yyyy") inside a LookupSet function.
It is not tested but should work.
Let me know if this helps.

DCount will nor return 0 but returns Error instead

Test = DCount("*", "tblWorkNew", "GP = " & GPID & " And Month = #" & Month & "#")
This function gives correct results when the answer is >0. Whenever it's 0, I get #Error. I have tried putting my code within a Nz but that doesn't help either.
I tried to duplicate on a Northwind db what I believe you are trying to do. I used the Order List form. In the header of that form I created a textbox named txtMonth. The Control Source for txtMonth is =Month([Order Date]). Then I created another textbox in the header named txtMonthOrders with Control Source as =GetMonthSum(). Then I created a function in Modules called GetMonthSum(). This is the function: GetMonthSum = DCount("[Order ID]", "Order Summary", "Month([Order Date]) = '" & Forms![Order List]!txtMonth & "'") . This seems to work.