无绑定窗体,recordset为主、子窗体的数据源,但无法设置设置链接主字段和链接子字段
Private Sub Form_Open(Cancel As Integer)
Dim cn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim rs3 As New ADODB.Recordset
'cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentProject.Path & "\a.mdb;Persist Security Info=False"
With rs1
.ActiveConnection = cn
.Source = "SELECT * FROM 表1"
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.Open
End With
With rs2
.ActiveConnection = cn
.Source = "SELECT * FROM 表2"
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.Open
End With
With rs3
.ActiveConnection = cn
.Source = "SELECT aa FROM 表3"
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.Open
End With
Set Me.Recordset = rs1
Set Me!窗体子窗体.Form.Recordset = rs2
'从这里开始出错
Forms!窗体.窗体子窗体.LinkMasterFields = "序号"
Forms!窗体.窗体子窗体.LinkChildFields = "序号"
End Sub