nbradleywilkerson
New Member
- Joined
- Apr 5, 2018
- Messages
- 1
Looking for help with why the vba code that is currently running to retrieve data from SQL server is not displaying all of the data that is being retrieved.
I have 28 programs in the columns which I am retrieving data for 15 categories in the rows. The data has been retrieving fine for the last 3 years without any issues but now the last column of data is not populating in the Excel workbook. I have confirmed the stored procedure is working properly in SSMS and the data is being retrieved.
Here is the code I am using to retrieve the data:
Function getDataDetail()
Dim evalConn As ADODB.Connection
Dim evalData As ADODB.RecordSet
Dim evalDataField As ADODB.Field
Set evalConn = New ADODB.Connection
Set evalData = New ADODB.RecordSet
evalConn.ConnectionString = conStrSQL
evalConn.Open
On Error GoTo CloseConnection
'Application.Workbooks("WorkBook.xlsm").Activate
'Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Responses by Program"
'Range("B" & Rows.Count).End(xlUp).Offset(3).Select
With evalData
.ActiveConnection = evalConn
.Source = GetSQLGetDataDetail
.LockType = adLockReadOnly
.CursorType = adOpenForwardOnly
.Open
End With
On Error GoTo CloseRecordset
' For Each evalDataField In evalData.Fields
' ActiveCell.Value = evalDataField.Name
' ActiveCell.Offset(0, 1).Select
' Next evalDataField
Sheets("Responses by Program").Select
Range("B" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.CopyFromRecordset evalData
'ThisWorkbook.Worksheets("Responses by Program").Cells.EntireColumn.AutoFit
On Error GoTo 0
CloseRecordset:
evalData.Close
CloseConnection:
evalConn.Close
End Function
Function GetSQLDataDetail() As String
Dim courseID As String
Dim classEndDate As Date
Dim fiscalYear As String
Dim sqlString As String
Dim SQL As String
SQL = Sheet1.Range("BC3").Text
sqlString = SQL
GetSQLDataDetail = sqlString
End Function
Any help with understanding why the data is not being retrieved into Excel would be greatly appreciated.
I have 28 programs in the columns which I am retrieving data for 15 categories in the rows. The data has been retrieving fine for the last 3 years without any issues but now the last column of data is not populating in the Excel workbook. I have confirmed the stored procedure is working properly in SSMS and the data is being retrieved.
Here is the code I am using to retrieve the data:
Function getDataDetail()
Dim evalConn As ADODB.Connection
Dim evalData As ADODB.RecordSet
Dim evalDataField As ADODB.Field
Set evalConn = New ADODB.Connection
Set evalData = New ADODB.RecordSet
evalConn.ConnectionString = conStrSQL
evalConn.Open
On Error GoTo CloseConnection
'Application.Workbooks("WorkBook.xlsm").Activate
'Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Responses by Program"
'Range("B" & Rows.Count).End(xlUp).Offset(3).Select
With evalData
.ActiveConnection = evalConn
.Source = GetSQLGetDataDetail
.LockType = adLockReadOnly
.CursorType = adOpenForwardOnly
.Open
End With
On Error GoTo CloseRecordset
' For Each evalDataField In evalData.Fields
' ActiveCell.Value = evalDataField.Name
' ActiveCell.Offset(0, 1).Select
' Next evalDataField
Sheets("Responses by Program").Select
Range("B" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.CopyFromRecordset evalData
'ThisWorkbook.Worksheets("Responses by Program").Cells.EntireColumn.AutoFit
On Error GoTo 0
CloseRecordset:
evalData.Close
CloseConnection:
evalConn.Close
End Function
Function GetSQLDataDetail() As String
Dim courseID As String
Dim classEndDate As Date
Dim fiscalYear As String
Dim sqlString As String
Dim SQL As String
SQL = Sheet1.Range("BC3").Text
sqlString = SQL
GetSQLDataDetail = sqlString
End Function
Any help with understanding why the data is not being retrieved into Excel would be greatly appreciated.