VBA错误 - 键入MisMatch

时间:2016-02-11 14:09:27

标签: sql vba

我不知道为什么Excel - VB表现得很愚蠢。我的工具有几个用户表单。在重命名命令按钮的标题之前,一切正常。我收到了类型错误匹配错误。该命令加载另一个表单。 form_initialise代码如下。当我在userform_initialise中注释掉代码的所有代码时它运行正常,但是当删除注释时#39;从所有行中它给我一个错误类型不匹配。

之前它工作得很完美,我的公司也在使用它。任何人都可以提供帮助。

  Private Sub UserForm_initialize()


  lstUser.AddItem Sheets("LAUNCH").Range("Z1").Value

  Application.ScreenUpdating = False

  Dim conn As Object
  Dim rs As Object
  Dim objMycmd As Object
  Dim rc As Long
  Dim sConnString As String
    ' Create the connection string.
    sConnString = "Provider=SQLOLEDB;Data Source=XXXXXXXX;" & _
                  "Initial Catalog=XXXXXX;" & _
                  "Integrated Security=XXXXXXXX;" & _
                  "User ID=XXXXXXXXXXXXXXXX;" & _
                  "Passsword=XXXXXXXXXXXXXXXXX;"
   ' Create the Connection and Recordset objects.
    Set conn = CreateObject("ADODB.Connection")
    ' Open the connection and execute.
    conn.Open sConnString



    Sql = "Select DISTINCT [Exec] from tblKPI3"
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open Sql, conn, adOpenStatic

    If rs.EOF Then
        MsgBox "No Records"
    Else
        rs.Movefirst
        If Sheets("LAUNCH").Range("AA1") = "Yes" Then
        With frmReport.lstUser
        .Clear
        Do
            .AddItem rs![exec]
            rs.MoveNext
        Loop Until rs.EOF
        End With
        End If
    End If


    rs.Close
    conn.Close
   end sub

0 个答案:

没有答案