首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

对象已封锁,不允许操作

2013-01-08 
对象已关闭,不允许操作。Private Sub lstSubFunc_Click()On Error GoTo errHWith lstSubFuncLoadFunc Fal

对象已关闭,不允许操作。


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类型的,也没有对它做关闭操作,为什么就不行了呢?
[解决办法]
引用:
执行到 RsFuncS.EOF 这里就报错

第一次运行,记录指针即到末尾,再次运行指针没有复位!
[解决办法]
测试一下循环 Do Until 过后,对象是否为 Nothing ,
同时设置.Rows = 1 和 RsFuncS.MoveFirst
  
[解决办法]

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



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

热点排行
Bad Request.