在主Form里添加了一个子窗体RWChildForm,以下是主窗体模块中的代码,运行到红色字体一行提示“对象变量或 With 块变量没有设置”,各位看下问题在哪里,说明下,RWRecordset是正常的,在调试窗口中输出内容正常
Option Compare Database
Dim RWRecordset As DAO.Recordset
Private Sub Form_Load()
Me.DTPicker2.Value = DateAdd("d", -1, Now)
Call GetSQLServerData
Me.RWChildForm.Form.Recordset = RWRecordset ,是不是.RWChildForm.Form.Recordset属性为空呢,如何修改呢,
End Sub
Private Sub GetSQLServerData()
Dim mydb As Database
Dim RWRecordset As Recordset
Dim wrkODBC As Workspace
Dim conZDZ As Connection
Set wrkODBC = CreateWorkspace("", "admin", "", dbUseODBC)
Set conZDZ = wrkODBC.OpenConnection("", , , _
"ODBC;Driver={SQL Server};Server=XXX.XXX.X.XX;UID=sa;PWD=sa;DATABASE=elnfo;")
strSQL = "Select....."
Debug.Print strSQL
Set RWRecordset = conZDZ.OpenRecordset(strSQL, dbOpenDynamic)
OpenRecordsetOutput RWRecordset
End Sub
Sub OpenRecordsetOutput(rstOutput As Recordset)
' Enumerate the specified Recordset object.
With rstOutput
Do While Not .EOF
Debug.Print , .Fields(0), .Fields(1), .Fields(2), .Fields(3)
.MoveNext
Loop
End With
End Sub