我做了一个数据库程序,在模块中有一个MAIN过程(启动程序),有个ENDSYSTEM过程(结束程序),但是总是有时候关闭程序时总是有时候重新启动,有时候关闭出错,而且是数据库的一个连接出错(strConn):意思是这个WITH未定义,但是我是关闭程序呀!它在结束过程中已经Set nothing 了.?

解决方案 »

  1.   

    在你的ENDSYSTEM过程中,这样处理一下:
    ....
    doevents  '让系统先做完现在的事情
    if rs.status=1 then '关闭记录集
       rs.close
    end if
    set rs=nothing
    if cn.status=1 then  '关闭数据库连接
       cn.close
    end if
    set cn=nothing
    doevents
    unload me
    .....
      

  2.   

    Dim i As Integer
        Dim frm As Form    '// Timer end
        If frmBill.tmrMark.Enabled Then
            frmBill.tmrMark.Enabled = False
        End If
        '// TB End
        If frmBill.TB.Enabled Then
            frmBill.TB.Enabled = False
        End If
        
        If Not pHead Is Nothing Then
            Set pHead = Nothing
        End If
        If Not pv Is Nothing Then
            Set pv = Nothing
        End If    '// End system,Give UOL SERVER to send QUIT command.
        If frmBill.WS_UOLS.State = sckConnected Then
            frmBill.WS_UOLS.SendData m_CMDQUIT
            Wait 1
        End If    '// Destruct Winsock
        For i = 0 To gSockets
            If frmBill.WS_GW(i).State <> sckClosed Then
                frmBill.WS_GW(i).Close
            End If
        Next i
        
        If frmBill.WS_UOLS.State <> sckClosed Then
            frmBill.WS_UOLS.Close
        End If
            
        For Each frm In Forms
            Unload frm
        Next
            
        If Not gRs Is Nothing Then
            gRs.Close
        End If
        Set gRs = Nothing
        
        If Not gDatabase Is Nothing Then
            gDatabase.Close
        End If
        
        Set gDatabase = Nothing
      

  3.   

    特别是关闭快速时,总是跳到窗体级过程中的记录集检索那里,FORM中:Private Sub RefreshGridMark()
        Dim sql As String
        Dim strClip As String
        Dim Cols As Integer
        Dim Rows As Integer
        
        Dim rs As New ADODB.Recordset
        
        strClip = Empty
        
        Rows = 0
        Cols = 2
        
        sql = "select * from Mark"
        
        Set gRs = New ADODB.Recordset
        Set gRs = gDatabase.Execute(sql)
        With gRs
            Do While Not .EOF
                strClip = strClip & .Fields("cIPCardNo") & vbTab & .Fields("mMark") & vbCr            Rows = Rows + 1
                .MoveNext
            Loop
            .Close
        End With
        Set gRs = Nothing
           
        ClipToGrid msfIpCard, strClip, Rows + msfIpCard.FixedRows, Cols
        
        cmdEdit(m_CMDDEL).Enabled = (msfIpCard.FixedRows <> msfIpCard.Rows)
        cmdEdit(m_CMDMARK).Enabled = (msfIpCard.FixedRows <> msfIpCard.Rows)
    End Sub
      

  4.   

    在说一下,我的窗体中有个时间控件,在时间空间中有个延迟,因为要发送命令所以wait 1
      

  5.   

    '延时
    Public Function Wait(i As Integer)
        Dim PauseTime, Start
              
        PauseTime = i   ' 设置暂停时间。
        Start = Timer   ' 设置开始暂停的时刻。
        Do While Timer < Start + PauseTime
            DoEvents   ' 将控制让给其他程序。
        Loop
    End Function
      

  6.   

    把这个去掉
     If Not gDatabase Is Nothing Then
            gDatabase.Close
     End If