Reputation: 875
In Report_Open() sub on the main report I have:
SQLstring = "Select * from dbo_NewPatient where id=49"
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(SQLstring, dbOpenDynaset, dbSeeChanges)
Now I want to update a Label caption in a subreport, On my subreport I have tried:
Private Sub Report_Open(Cancel As Integer)
Labal1.Caption = Me.Parent.rs("index")
End Sub
But Me.Parent.rs("index") doesn't work, I've tried multple iterations of the Me!, Me.[ and things like that, but can't seem to find what the syntax should be. How would i update this Label1.Caption?
I'm going to have multiple subreports, so that's why I have the SQL command on the main report, I didn't want to have to call the SQL command on each subreport.
Thanks for any help or direction!
Upvotes: 0
Views: 870
Reputation: 19367
I am not sure what your intention is with the Recordset, you haven't shown any code that does something with it.
If your intention is to set the Recordset
property of the (main) Report then I don't believe this will work:
Me.Recordset = rs
The Help system is not very clear about this, but when this is attempted Access displays an error stating that this feature is only available in ADP (a defunct technology).
I would set the RecordSource
property of the Report to your sql-statement:
Me.RecordSource = sqlString
Alternatively, you can set this to "SELECT * FROM dbo_NewPatient" and use the id of 49 as a Filter
.
If the "index" on the main form is in the Detail section, then you cannot refer to it directly from your subreport. Add a hidden textbox to, perhaps, the main report's ReportHeader
that refers to the control in the Detail section:
=[txtIndex]
In the subreport's Open even you can refer to this control, assuming it is named "txtIndex_ref":
Label1.Caption = Me.Parent.Controls("txtIndex_ref")
Upvotes: 1
Reputation: 5719
Try to declare a Public var ..
Public rs As Recordset '--------
SQLstring = "Select * from dbo_NewPatient where id=49"
Set rs = CurrentDb.OpenRecordset(SQLstring, dbOpenDynaset, dbSeeChanges)
So you can do
Private Sub Report_Open(Cancel As Integer)
lblIndex.Caption = rs("index")
End Sub
Upvotes: 0