Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
a = MsgBox("确实要退出该窗体吗?", vbYesNo, "询问")
If a = vbYes Then
If rs.State = adStateOpen Then
rs.Close
Set rs = Nothing
End If
con.Close
Set con = Nothing
Cancel = 0
Else
Cancel = 1
End If
End Sub哪里有错。

解决方案 »

  1.   

    从代码看,没有错con.Close
    这一句有点问题,除非你能肯定连接是出于打开状态另外,强烈建议不要使连接长久保持打开状态,
    应该用完及时关闭,
    短时间内再打开,可以从连接池得到,不会损失性能的
      

  2.   

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    if MsgBox("确实要退出该窗体吗?", vbYesNo, "询问") = vbYes Then
       If rs.State = adStateOpen Then
          rs.Close
          Set rs = Nothing
          con.Close
          Set con = Nothing
       end if
    Else
       Cancel = 1
    End If
    End Sub
    小改一下,楼主试试看。