用户定义的类型未定义VBA

时间:2017-06-01 06:18:32

标签: vba

存在编译错误

  

'用户定义的类型未定义'

当我尝试编译此代码时,我进入了VB6。谁能告诉我我需要做些什么来解决这个错误?以下是我收到错误的行: 这是我的代码:

Private Sub CommandButton1_Click()
    Set cnnConnection = New ADODB.connection

    cnnConnection.Open ("Provider=SQLOLEDB; " & _"data Source=180.125.20.96;" & _"Initial Catalog=path_test; " & _"User Id=sa;Password=Psword4886")
    rstRecordset.Open "Select * from REM_M_Pojhd where PRJCDE =@PRJCDE", cnnConnection, _adOpenKeyset, adLockOptimistic

    Dim command As New SqlCommand("Select * from REM_M_Prjhdrimg where PRJCD =@PRJCD", connection)
    command.Parameters.Add("@PRJCD", SqlDbType.VarChar).Value = TextBox1.Text
    Dim table As New DataTable()
    Dim adapter As New SqlDataAdapter(command)

    adapter.Fill (table)

    If table.Rows.Count() <= 0 Then
        MessageBox.Show ("No Image For This Id")
    Else
        TextBox1.Text = table.Rows(0)(0).ToString()
        TextBox2.Text = table.Rows(0)(1).ToString()
        TextBox3.Text = table.Rows(0)(2).ToString()
        Dim img() As Byte
        img = table.Rows(0)(3)
        Dim ms As New MemoryStream(img)
        Image1.Image = Image.FromStream(ms)
    End If
End Sub

我不是一个知识渊博的程序员,我还只是一个学生,请用一些详细的陈述来解释它。 谢谢!

1 个答案:

答案 0 :(得分:1)

我假设你的代码的前3行(VBA / VB6)和其余的VB.Net之间应该有差距。

在VBA Set cnnConnection = New ADODB.connection失败时,用户定义的类型未定义,因为您尚未添加对 Microsoft ActiveX Data Objects Library 2.x 的引用ADODB.connection在编译时不知道。