Private Sub lstSubFunc_Click()
On Error GoTo errH
With lstSubFunc
    LoadFunc = False
    If .Row < 0 Then .Row = 0
    If .TextMatrix(.Row, 1) = "" Then Exit Sub
    curFunctionID = .TextMatrix(.Row, 1)
    If curFunctionID = 0 Then Exit Sub
    
    .Cell(flexcpFontBold, 1, 0, .Rows - 1, 0) = 0
    .Cell(flexcpFontBold, .Row, 0, .Row, 0) = 1    RsFuncS.Filter = "FSUBFUNCID = " & curFunctionID
    If RsFuncS.EOF Then
        lstDetailFunc.Visible = False
        Exit Sub
    Else
        lstDetailFunc.Visible = True
    End If
    ImgArrowS.Move lstSubFunc.CellLeft, lstSubFunc.CellTop + ImgArrowS.Height / 4
    ImgArrowD.Move 0, lstDetailFunc.RowHeightMin + ImgArrowD.Height / 4
End With
With lstDetailFunc
    .Rows = 1
    RsFuncS.MoveFirst
    Do Until RsFuncS.EOF
        .AddItem Space(3) & RsFuncS(1) & Chr(9) & RsFuncS(0)
        RsFuncS.MoveNext
    Loop
    .Row = 1
    LoadFunc = True
    '.Height = .Rows * .RowHeightMin + 100
    .Move .Left, lstSubFunc.Top + lstSubFunc.CellTop
    '.Height = Me.ScaleHeight - .Top - 600
    .Height = Me.ScaleHeight - .Top
End With
errH:
If err.Number <> 0 Then
     MsgBox err.Description, 64
     Exit Sub
End If
End Sub
Public RsFuncS As ADODB.Recordset
第一次执行lstSubFunc_Click正常,第二次执行lstSubFunc_Click就报错“对象已关闭,不允许操作。”,我这个是Public类型的,也没有对它做关闭操作,为什么就不行了呢?

解决方案 »

  1.   

    执行到   RsFuncS.EOF  这里就报错
      

  2.   

    那也应该是   RsFuncS.EOF =True   而不会报“对象已关闭,不允许操作。”才对啊
      

  3.   

    测试一下循环 Do Until 过后,对象是否为 Nothing ,
    同时设置.Rows = 1 和 RsFuncS.MoveFirst
      
      

  4.   


    Private Sub lstSubFunc_Click()
    On Error GoTo errH
    With lstSubFunc
        LoadFunc = False
        If .Row < 0 Then .Row = 0
        If .TextMatrix(.Row, 1) = "" Then Exit Sub
        curFunctionID = .TextMatrix(.Row, 1)
        If curFunctionID = 0 Then Exit Sub
        
        .Cell(flexcpFontBold, 1, 0, .Rows - 1, 0) = 0
        .Cell(flexcpFontBold, .Row, 0, .Row, 0) = 1    RsFuncS.Filter = "FSUBFUNCID = " & curFunctionID
        If RsFuncS.EOF Then
            lstDetailFunc.Visible = False
            Exit Sub
        Else
            lstDetailFunc.Visible = True
        End If
        ImgArrowS.Move lstSubFunc.CellLeft, lstSubFunc.CellTop + ImgArrowS.Height / 4
        ImgArrowD.Move 0, lstDetailFunc.RowHeightMin + ImgArrowD.Height / 4
    End With
    With lstDetailFunc
        .Rows = 1
        if Not RsFuncS.BoF Then RsFuncS.MoveFirst
        Do 
            .AddItem Space(3) & RsFuncS(1) & Chr(9) & RsFuncS(0)
            RsFuncS.MoveNext
        Loop Until RsFuncS.EOF
        .Row = 1
        LoadFunc = True
        '.Height = .Rows * .RowHeightMin + 100
        .Move .Left, lstSubFunc.Top + lstSubFunc.CellTop
        '.Height = Me.ScaleHeight - .Top - 600
        .Height = Me.ScaleHeight - .Top
    End With
    errH:
    If err.Number <> 0 Then
         MsgBox err.Description, 64
         Exit Sub
    End If
    End Sub
      

  5.   

    写数据库都要形成这样的习惯,要判断.BOF和.EOF状态,然后才能开始操作,这些都是针对数据安全的