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.
精彩评论