1

在 Microsoft Access 2007 中是否可以手动生成 RecordSet 对象并将对象传递给 Microsoft Access 报表和子报表?

我想要一个表单,用户在该表单上单击一个按钮,OnClick 事件会动态创建两个 RecordSet,打开一个 Report 并将第一个 RecordSet 附加到 Report 并将第二个 RecordSet 附加到该 Report 的 SubReport。然后生成/显示报告。

谢谢。

4

1 回答 1

1

您可以将表单或报表的记录源设置为 SQL 字符串。您还可以使用 OpenForm 或 OpenReport 的 WHERE 参数根据现有查询或表过滤表单或报表。最后,您可以将表单的记录集设置为现有的记录集,但这比将记录源设置为 sql 稍微复杂一些。

  sSQL = "SELECT [" & Me.AField & "] FROM [" & Me.ATable & "] " _
       & "WHERE [" & MeAnotherField & "] " & Me.Operator & Me.Value

  Forms!AnotherForm.Recordsource = sSQL

断开连接的记录集

Private Sub Form_Load()
Set rs = New ADODB.Recordset ''CreateObject("ADODB.RECORDSET")

 With rs
    'Set .ActiveConnection = cn
    .LockType = adLockOptimistic
    .CursorType = adOpenKeyset
 End With

'Create arrays from the lists
asL1 = Split("a,b,c,", ",")
asL2 = Split("b,e,c,d", ",")

'Create a disconnected recordset
rs.Fields.Append "Srt", adVarChar, 25
rs.Fields.Append "L1", adVarChar, 25
rs.Fields.Append "L2", adVarChar, 25

rs.Open

'Add list 1 to the recordset
For i = 0 To UBound(asL1)
    rs.AddNew Array("Srt", "L1"), Array(asL1(i), asL1(i))
    rs.Update
Next

rs.Sort = "Srt"

Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
End Sub
于 2013-01-25T10:26:53.673 回答