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

对象已关闭,不允许操作。该如何处理

2012-06-13 
对象已关闭,不允许操作。VB codePrivate Sub lstSubFunc_Click()On Error GoTo errHWith lstSubFuncLoadFun

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

VB code
Private Sub lstSubFunc_Click()On Error GoTo errHWith 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    [color=#FF0000]RsFuncS[/color].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 / 4End WithWith 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 - .TopEnd WitherrH:If err.Number <> 0 Then     MsgBox err.Description, 64     Exit SubEnd IfEnd Sub


Public RsFuncS As ADODB.Recordset
第一次执行lstSubFunc_Click正常,第二次执行lstSubFunc_Click就报错“对象已关闭,不允许操作。”,我这个是Public类型的,也没有对它做关闭操作,为什么就不行了呢?

[解决办法]
探讨
执行到 RsFuncS.EOF 这里就报错

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

[解决办法]
VB code
Private Sub lstSubFunc_Click()On Error GoTo errHWith 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    [color=#FF0000]RsFuncS[/color].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 / 4End WithWith 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 - .TopEnd WitherrH:If err.Number <> 0 Then     MsgBox err.Description, 64     Exit SubEnd IfEnd Sub
[解决办法]
写数据库都要形成这样的习惯,要判断.BOF和.EOF状态,然后才能开始操作,这些都是针对数据安全的

热点排行