Sub MultiResultProcTest()
Dim Conn As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim Cmd As New ADODB.Command
Dim Row As Long
Dim Findex As Long
Dim Data As Worksheet
Dim X As Long
Dim Server As String
On Error Resume Next
Application.Calculation = xlCalculationManual
Set Data = Sheets(ActiveSheet.Name)
Data.Select
Server = "REMOVED"
DatabaseUserName = "REMOVED"
DatabasePassword = "REMOVED"
Conn.Open "PROVIDER=SQLOLEDB;DATA SOURCE=" & Server & ";USER ID=" & DatabaseUserName & ";PASSWORD=" & DatabasePassword
Cmd.ActiveConnection = Conn
Cmd.CommandType = adCmdText
Cmd.CommandText = "StoredProc '%9332727018176%'"
Set RS = Cmd.Execute
For Y = 1 To 4
For X = 0 To RS.Fields.Count - 1
Data.Cells(1 + (Y * 4), X + IIf(ActiveSheet.Name = "Main", 1, 2)) = RS.Fields(X).Name
Next
'If the result set is smaller than the sheet then populate in one go otherwise post line by line until the sheet is full
If RS.RecordCount < Rows.Count Then
Data.Cells(Row + 1 + (Y * 4), Findex + IIf(ActiveSheet.Name = "Main", 1, 2)).CopyFromRecordset RS
Else
Do While Not RS.EOF
Row = Row + 1
For Findex = 0 To RS.Fields.Count - 1
Data.Cells(Row + 1 + (Y * 4), Findex + IIf(ActiveSheet.Name = "Main", 1, 2)) = RS.Fields(Findex).Value
Next Findex
RS.MoveNext
Loop
Row = 0
End If
RS.NextRecordset 'This and the loop it is in are what I added to try and get it to work.
Next
Application.Calculate
Application.Calculation = xlCalculationAutomatic
End Sub