Greetings
I am trying to extract data from SQL Server using Excel VBA.
Below is the code which errors out @ the Rs.Open StrSQL, Con
As far as having any security issues -
I have admin rights and opening and connecting through either Excel or Access work fine.
I can run SQL queries all day from Access but for this project I need to use Excel
Thanks for any help you can provide.
I am trying to extract data from SQL Server using Excel VBA.
Below is the code which errors out @ the Rs.Open StrSQL, Con
Code:
Sub DbConnection()
Dim Con As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim Fld As ADODB.Field
Dim StrSQL As String
Dim Wb As ThisWorkbook
Dim Ws As Worksheet
Dim StrCon As String
Set Wb = ThisWorkbook
Set Ws = Wb.Sheets("Sheet2")
Set Con = New ADODB.Connection
Set Rs = New ADODB.Recordset
StrCon = "ODBC;Data Source=ABCD23NNP_LIST\SQL2014,1433;DSN=RAOC_SQLTST;APP=Microsoft Excel;DATABASE=RAOCStatsTrain;UID=;PWD=;Trusted_Connection=yes;"
StrSQL = "SELECT [ReportDate] ,[WorkType] ,[TotalCases]" & _
"FROM [RAOCStats].[tri].[tblCRTimeliness]" & _
"WHERE BatchID >= '20181219_050000' AND BatchID <= '20181219_051500'"
'''''StrCon = "ODBC;Data Source=AGUTIL14P_LIST\SQL2014,1433;DSN=RAOC_SQLPRD;DATABASE=RAOCStats;UID=;PWD=;Trusted_Connection=yes;"
Con.ConnectionString = StrCon
Con.Open
Rs.Open StrSQL, Con<-----Errors on this line
As far as having any security issues -
I have admin rights and opening and connecting through either Excel or Access work fine.
I can run SQL queries all day from Access but for this project I need to use Excel
Thanks for any help you can provide.