0

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!

4

2 回答 2

1

我不确定您对 Recordset 的意图是什么,您没有显示任何对其进行处理的代码。

如果您打算设置Recordset(主)报告的属性,那么我认为这不会起作用:

Me.Recordset = rs

帮助系统对此不是很清楚,但是当尝试这样做时,Access 会显示一个错误,指出此功能仅在 ADP(一种已失效的技术)中可用。

我会将RecordSourceReport 的属性设置为您的 sql 语句:

Me.RecordSource = sqlString

或者,您可以将其设置为“SELECT * FROM dbo_NewPatient”并使用 49 的 id 作为Filter.

如果主窗体上的“索引”位于详细信息部分,则您不能直接从子报表中引用它。将一个隐藏的文本框添加到主报告ReportHeader中,该文本框可能引用了 Detail 部分中的控件:

=[txtIndex]

在子报表的 Open 中,你甚至可以引用这个控件,假设它被命名为“txtIndex_ref”:

Label1.Caption = Me.Parent.Controls("txtIndex_ref")
于 2013-07-05T16:01:28.687 回答
0

尝试声明一个 Public var ..

Public rs As Recordset '--------

SQLstring = "Select * from dbo_NewPatient where id=49"
Set rs = CurrentDb.OpenRecordset(SQLstring, dbOpenDynaset, dbSeeChanges)

所以你可以做

Private Sub Report_Open(Cancel As Integer)
    lblIndex.Caption = rs("index")
End Sub
于 2013-07-05T16:02:03.253 回答