Excel VBA not retrieving all data from SQL Server.

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.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top