<rk***@ktri.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I need the conncetion string to place inside of vba code to connect to
a sql server. This is require so that I can add data to a table or
delete data from a table dependenting on the vba 'if-else' condition.
This is a fairly basic question and there must be a million examples posted.
Here is an example which creates a connection where the SQL Server has been
configured to accept connections using Windows Integrated security. If this
is not the case, look at the following for variations:
http://www.carlprothman.net/Default....erForSQLServer
Private Sub cmdTest_Click()
On Error GoTo Err_Handler
Dim cnn As ADODB.Connection
Dim strConn As String
strConn = "Provider=sqloledb;" & _
"Data Source=MyServer;" & _
"Initial Catalog=MyDatabase;" & _
"Integrated Security=SSPI"
Set cnn = New ADODB.Connection
cnn.Open strConn
MsgBox cnn.ConnectionString, vbInformation
Exit_Handler:
If Not cnn Is Nothing Then
If cnn.State <> adStateClosed Then
cnn.Close
End If
Set cnn = Nothing
End If
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub