Subreport visibility based on record count>0 - ms-access

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

Related

How to make a image visible based on a value from a combo box/Text Box in a Access Report?

I have the report mostly working and setup the way I want it but I'm running into a issue where there are two signatures used on the report.. I want the report to show only the signature selected based on a combo box value? The Value is coming into the report but the code I did in VBA in the Event of On Open isn't making my signatures visible... what am I doing wrong? This is what I'm using... My combobox on the report is called cboSelectSignatureToUse and the images in the report is called imgGailSig and imgDanSig. Heres the code I tried with no luck.
If Me.cboSelectSignatureToUse.Value = "Dan" Then
Me.imgDanSig.Visible = True
Me.ImgGailSig.Visible = False
Else
Me.ImgGailSig.Visible = True
Me.imgDanSig.Visible = False
End If
Can use OnLoad event if report is filtered to a single record.
If multiple records are pulled, use OnFormat or OnPrint event of section that contains the image control.
Consider:
Me.ImgGailSig.Visible = Me.cboSelectSignatureToUse.Value = "Gail"
Me.imgDanSig.Visible = Me.cboSelectSignatureToUse.Value = "Dan"

MS Access 2016: Set Report's RecordSource to get data from a Subform

Is there some sort of work-around that could make this possible? Or could anyone offer just some general advice on my situation below? I tried to set the record source through VBA but had no luck.
My situation:
I have a main form with a subform contained within, and I want the subform to be purely for data entry (Data Entry = Yes). Upon clicking a button, the user is sent from the main form to a report (print preview only). I want the source for this report to be the subform the users are entering data into, but I don't have this option from the report's property sheet itself (no forms), and I also was unable to set it through VBA. Here's my code, it's one line so I highly doubt it's the problem.
Private Sub Report_Load()
Reports![P18003 SDR Report].RecordSource = "P18003 SDR Subform"
End Sub
Previously, to work-around this I had a parameter query that waited for the user to enter data into an unbound textbox from the main form, and an after update trigger on that textbox would load any data relevant to that parameter (my employer and I miscommunicated the requirements).
It turns out though that I don't need to load any older data, and I run into problems with my current parameter query in the event that the user does input a parameter which loads old data - that old data is transferred to the report in addition to the new data they've just entered. This is the main problem with the method I am currently using, and it trashes almost all functionality with this form and report. The events that a user would need to enter a parameter which queries older data are few and far between, but it's not a functional product unless I can get the subform to be connected to the report directly. There's likely something obvious I'm missing here (or at least, I hope there is).
Thanks in advance for taking the time to read this and for any help you may offer.
you can either send the recordsource to the report itself in the OpenArgs by the open report event, after the click event in the subform
Private Sub btnSubform_Click()
Dim strSQL as String
strSQL = "SELECT * FROM SubformQuery WHERE ID = " & CurrentSubfromRecordID
Docmd.OpenReport, acViewReport, , , , strSQL
End Sub
and then in the Report.
Private Sub Report_Open(Cancel As Integer)
Me.recordsource = Me.OpenArgs
End Sub
Or you can make a paramter Query and set this Query criteria as record source for the report. So the parameter in the query is pointing to the current selected row in the subform. Like this:
--- At the Criteria in the Query designer:
--- RecordSource for the Report:
Forms![FormMain]![YourSubform]![ID]
Now every time the reports obens he gets the ID from the current selected record of your subform.

MS Access: Report SetProperty On Activate does not work, on batch print

VBA Version
Report On Activate Event
Option Compare Database
Private Sub Report_Activate()
If (Me.SomeTextBox = "SomeText25") Then
Me.SomeLabel.Visible = False
End If
End Sub
Macro Version
Report On Activate Event
If [SomeTextBox]=SomeText25 Then
SetPropery
Control Name SomeLabel
Property Visible
Value False
End If
The Report Previews and Prints as desired, from Print Preview and Report View, as a single Report, but not when Printing multiple results programmatically, from the same Query Data.
Query Criteria: Between...
When the Report Prints multiple records, the control is visible on all Printed Reports, with the On Activate Event being ignored.
It's looking like I may have to Loop through the records set, to get the desired results.
As a work around, I converted the Label to a TextBox, and am using Conditional Formatting, to hide (White out), the text.
The OnActivate doesn't fire for normal printing, only for preview, so you will have to use another event.
Putting my If/Then, in the On Print Event, of the Detail Section, with an Else to reset it, Prints all Reports correctly.
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)`
If...Then
...Visible = False
Else
...Visible = True
End IF
End Sub

SSRS Passing a GUID to a Parameter in a Sub Report

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

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.