有这样的一个问题,在一个窗体上,如何显示多个子窗体,而且子窗体是同一个窗体,显示不相同的数据,希望还有计算功能。
这里我们用的是是动态绑定子窗体,用ADO去求和。下面的示例是绑定不同的景点的信息,然后求和。希望能起到一个引导思路的作用.
Private Sub Form_Open(Cancel As Integer)
Dim sql As String
sql = "Select top 20 * from 景点表 Where True Order By ID"
Call RequerySubForm(sql)
End Sub
Private Sub RequerySubForm(sql As String)
On Error GoTo Err_RequerySubForm
Dim rs As New ADODB.Recordset
Dim i As Integer
rs.Open sql, CurrentProject.Connection, 1, 3, 512
For i = 1 To 20
Me.Controls("Child" & i).SourceObject = ""
Me.Controls("Child" & i).Visible = False
Next
i = 1
Do While Not rs.EOF
Me.Controls("Child" & i).SourceObject = "景点"
Me.Controls("Child" & i).Form.Filter = "ID=" & rs!ID
Me.Controls("Child" & i).Form.FilterOn = True
Me.Controls("Child" & i).Visible = True
i = i + 1
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Exit_RequerySubForm:
Exit Sub
Err_RequerySubForm:
MsgBox Err.Description, vbExclamation
Resume Exit_RequerySubForm
End Sub