Public Sub intTreeData()
Dim objNode As Node
    Dim objRecordset As ADODB.Recordset
    Dim objSubRecordset As ADODB.Recordset
    Dim strSQL As String
    Dim strClass As String
    
    TreeView1.Nodes.Clear
    
    '显示根节点
    strClass = "避雷器在线监测"
    TreeView1.LineStyle = tvwRootLines
    '查询线路
    strSQL = "select distinct 线路 from 参数表 order by 线路"
    Set objRecordset = ExecuteSQL(strSQL)
    '查询参数
    strSQL = "select distinct 线路,参数 from 参数表 order by 线路,参数"
    Set objSubRecordset = ExecuteSQL(strSQL)
    
    objRecordset.MoveFirst       这里显示错误  对象变量或with变量未设置
    '将参数信息添加到TreeView控件中
    Do Until objRecordset.EOF
        objSubRecordset.MoveFirst
        Set objNode = TreeView1.Nodes.Add(, , strClass, objRecordset.Fields(0))
        
        Do While Not objSubRecordset.EOF
            If objSubRecordset.Fields(0) = objRecordset.Fields(0) Then
                Set objNode = TreeView1.Nodes.Add(strClass, tvwChild, , _
                                objSubRecordset.Fields(1))
            End If
            objSubRecordset.MoveNext
        Loop
        
        strClass = strClass & "1"
        objRecordset.MoveNext
    Loop
    
    objSubRecordset.Close
    objRecordset.Close
    Set objRecordset = Nothing
    Set objSubRecordset = Nothing
End Sub问题出现在红字那里,求各位大神求解

解决方案 »

  1.   

    ExecuteSQL没有返回有效的Recordset对象。天知道ExecuteSQL你怎么写的。
      

  2.   

     objRecordset.MoveFirst       '这一句是多余的。另外,要解决你的问题,需要查看你的 Connection 对象是否正确打开,以及 ExecuteSQL 函数是否正确执行了 RecordSet 对象的打开操作。
      

  3.   

    不知道你有没有定义连接对象,可以定义一个dim cn as new ADODB.connection,Set cn = New ADODB.Connection,cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\你的数据库名称.mdb;Jet OLEDB:Database Password=;Persist Security Info=False;",哦,先工程中引用一下,,,仅供参考