开发者

Connectivity between SQL server and VBA

I am not able to establish c开发者_Go百科onnection between SQL server and a VBA form. It's throwing the following error

Compiler Error: User-defined type not defined

Here's the code with server details:

Private Sub CommandButton1_Click()
  Dim cnn As ADODB.Connection
  Dim cnn As ADODB.Command
  Set cnn = New ADODB.Connection
  Set cnn = New ADODB.Command
  cnn.Open "Provider=sqloledb;" & _
           "Data Source=<IP>;" & _
           "Initial Catalog=<DB>;" & _
           "User Id=<USER>;" & _
           "Password=<PASS>"
  MsgBox "connection successful"
  cnn.Close

End Sub


You need to add a reference to Microsoft ActiveX Data Objects X.X Library where X.X is the ADO version.

You will then get an error on your second line because you are trying to re-declare your cnn variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜