代码如下:Public Cnn As New ADODB.Connection  '连接对象
Public Sub Cnn_db()
     Dim Cnn As String '连接字符串
     strCnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=CabaretManageSystem;Data Source=HKZJZ-1613CE7C6"
    If Cnn.State = 1 Then  '如果连接打开,则关闭
    Cnn.Close
    End If
    Cnn.CursorLocation = adUseClient  '指定游标为客户端
    Cnn.Open strCnn                 '打开物理连接
End Sub光标停在第六行(If If Cnn.State = 1 Then 的 Cnn 处)谢谢!

解决方案 »

  1.   

    重复声明导致的Public Cnn As New ADODB.Connection  '连接对象
    Public Sub Cnn_db()
         Dim strCnn As String '连接字符串
         strCnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=CabaretManageSystem;Data Source=HKZJZ-1613CE7C6"
        If Cnn.State = 1 Then  '如果连接打开,则关闭
        Cnn.Close
        End If
        Cnn.CursorLocation = adUseClient  '指定游标为客户端
        Cnn.Open strCnn                 '打开物理连接
    End Sub
      

  2.   

    Public Cnn As New ADODB.Connection  '连接对象
    Dim Cnn As String '连接字符串//Cnn重复声明
      

  3.   

    建议楼主
    点菜单打开工具-选项
    编辑器
    代码设置
    选上要求变量声明的复选框,
    这样会在代码前面自动加上
    Option Explicit,
    编译时就可自动找到重复声明之类的错误