You are on page 1of 1

Public Sub ConnectionStringX()

'This was set up using Microsoft ActiveX Data Components version 2.8

Dim cnt As ADODB.Connection


Dim rst As ADODB.Recordset
Dim stSQL As String
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim rnStart As Range

Set cnt = New ADODB.Connection


cnt.connectionString = "driver={SQL Server};" & _
"server=36.67.16.235;uid=sa;pwd=Etamasa2017;database=simda2018"
Set wbBook = ActiveWorkbook
Set wsSheet = wbBook.Worksheets(2)

With wsSheet
Set rnStart = .Range("A1")
End With

stSQL = "SELECT * FROM ref_Rek_5"

'Set cnt = New ADODB.Connection

With cnt
.CursorLocation = adUseClient
.Open stADO
.CommandTimeout = 0
Set rst = .Execute(stSQL)
End With

'Here we add the Recordset to the sheet from A1


rnStart.CopyFromRecordset rst

'Cleaning up.
rst.Close
cnt.Close
Set rst = Nothing
Set cnt = Nothing

End Sub

You might also like