SSRS Passing a GUID to a Parameter in a Sub Report - reporting-services

I've configured a line item in a report to act as a hyperlink to a sub report (Placeholder Properties > Action > Go to report). One of the parameters that I want to pass to the sub report is a GUID.
I've configured the parameter value as follows:
=Fields!GuidParameter.Value
The sub report is being called and displayed but the parameter on the sub report isn't being set. The user has to manually select the parameter value on the sub report.

I think this is because of a case mismatch between the parent report (lower case GUID) and the sub report (expects upper case GUID).
I fixed it by specifiying the parameter value as:
=UCase(CType(Fields!GuidParameter.Value, GUID).ToString())

Related

Subreport visibility based on record count>0

I have an Access 365 report that contains 3 subreports. I would like to make one of the subreports visible, only if it contains data.
My plan was to use a control that contains a count of records in this subreport. If that count is zero, then set visibility of the subreport to false.
The subreport is called "NegConsentOutputAccounts_subreport"
The control with the record count is "text45" in the main report (placeholder while I work this out)
I thought I could get away with something as simple as:
Private Sub Report_Open(Cancel As Integer)
If Me.Text45 = 0 Then
Me.NegConsentOutputAnnuity_subreport.Visible = False
Else
Me.NegConsentOutputAnnuity_subreport.Visible = True
End If
End Sub
But apparently not. Triggering the report yields no visible action. No error message. Removing/commenting the code and the report is generated as expected.
I verified that the text45 control is variable. I get the same result whether the value is zero or non-zero.
Thanks in advance for any assistance.
SC

Access Report, get value from parent report

I have a report. Within that report is a sub report. And, there's a sub report within the first sub report. Anyway, each report has a stored query as its data source. The structure looks like this:
Main Report
Sub Report 1
Sub Report 2
I would like the stored query in Sub Report 2 to reference a field in Sub Report1. But, every time I run the report, I get a message box asking for the value. Here is the bit in my query that references the field:
[Reports]![MainReport]![SubReport1]!Report![Text70].value
Anyone know the correct syntax?
Not sure why, but leaving off value seems to have done it.
So, just something like: [Reports]![MainReport]![SubReport1]!Report![Text70] works.

Access: Refer to text box from detail section of subreport from main report

I can successfully refer to the value in a text box in the subreport footer using [subreportName].[Report].[textBoxName]. However, I would like to refer to a text box in the detail section. Using the above just gives the last value it contained - I would like to refer to a specific one (by field, say).
Is this possible, or is there some workaround?
Update: This is what I have so far. fieldA is the name of the text box that I want to use to pick out the correct entry (the correct entry will have "keyString" in this text box), and fieldB contains the value I want to actually store.
In the OnFormat event in the subreport detail section:
Dim varToStore As Double
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me![fieldA] = "keyString" Then
varToStore = Me![fieldB]
End If
End Sub
In a new Module:
Function getVariable(Name As String)
If Name = "varToStore" Then
getVariable = varToStore
Else
getVariable = -1
End If
End Function
In the Control Source of the text box in the main report:
=getVariable("varToStore")
I'm using the general function getVariable since there are a few variables from the detail section that I'm planning to store, so I thought it would be easier to just pass arguments to one function, rather than having a function for each.
If you look at a textbox in the detail section of a continuous form, it is really only one object, even if there are many rows on the screen.
If you change a property, you change all rows. If you read its value, you get the value of the current record.
With the detail section of a report, it's similar. You can't refer to the textbox of any row except the last after it has been printed.
But you can while it is being printed. The OnFormat property of the detail section is most probably the best event to use.
Something like
Private Sub Detailbereich_Format(Cancel As Integer, FormatCount As Integer)
If Me!Keyfield = 4711 Then
' do something specific with the textbox of this specific row
End If
End Sub
To create this sub, open the property sheet of the details section of the subreport.
On the Events tab, select Event procedure for the On Format event. Edit it ("..." button) and you're there.
You can assign the textbox value to a public variable to pass it to the main report. But depending on where/when in the main report you want to use it, it may be too late.
New answer for the Update.
I assume your code doesn't work?
That would be because getVariable("varToStore") is evaluated when the main report is opened, but varToStore is set later, when the subreport is formatted.
So you need a different approach. Don't try to fish your data from the subreport, get it with SQL when the main report is opened. Something like:
Report_Open()
Me.mainTextField.Value = DLookup("fieldB", "SubReportTable", "fieldA = 'keyString'")
mainTextField would be unbound then.
If "keyString" is actually constant, you could even use the DLookup as control source. But I guess it's a variable, so it's easier to construct the DLookup call in VBA.

Display different footer in main report of SSRS based on sub report

I have a main report in which there are two sub reports and then those two sub reports each contain one sub-subreport.
The following will give you an idea
Main Report
----->Sub Report 1
------------>Sub Sub Report 1
----->Sub Report 2
------------>Sub Sub Report 1
I am trying to display name of subreport in footer of main report depending on which subreport user is currently in. So let's say if user is viewing Sub Report 1 then it should display in footer of main report "Sub Report 1" (this is actually coming from database and is not like displaying some static text but for the time being ignore this)
If user is viewing Sub Sub Report 1 then footer of main report should say "Sub Report 1: Sub Sub Report 1"
After searching a bit I found out that:
Sub report footer will not be shown in Main report hence this option is ruled out
You cannot pass parameter from sub report to main report so this option is also ruled out
But looks like you can use Shared Variables between Sub Report and Main Report. I tried to do this but looks like it doesn't work. Here's what I did:
In my Sub Report 1 I declared a shared variable as below:
Public Shared Dim sharedVariable as String = "Sub Report 1"
Now in my Main Report I wrote the following function in code just to test if it prints it on screen on not.
Public Function PrintSharedVariable() as String
Return sharedVariable
End Function
But when I run this report, it shows error that sharedVariable is not declared in Main Report. How do I use shared variables and will it work in my case?

MS Access How can I show the query name in a report

If I make a report in MS Access then it is possible to let the program automatically fill in the name of the report, the actual time, the name of the report etc with the help of the code [name] Date() Time()
My question is if it is also possible that the program shows the query name (which is used for the report) on the report.
I have some reports on which I frequently change the query and it would be nice if the report automatically shows the name from the used query.
This method worked for me with Access 2003.
I added an unbound text box, txtRecordSource, to the report footer. Then used this for the footer's format event.
Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
Me.txtRecordSource = Me.RecordSource
End Sub