I have a very simple
VB Application I am trying to create. I have gotten it to work in terms of queries in SQL Server but I am having trouble moving it into Visual Basic. I need to resolve this in the next day or two. Any help is greatly appreciated. I am more of a database person than a front-end person.
It keeps blowing up at this line:
varData = rstCountErrors.GetRows(iNumRows)
This is my entire code:
Private Sub dgdCount_Click()
End Sub
Private Sub cmdGetErrorRecordDetail_Click()
Dim rstCountErrors As Object
Dim cnn As String
Dim strSQL As String
Dim fldCount As Integer
Dim intIRow As Integer
Dim intICol As Integer
Dim varData As Variant
'Create recordset and populate
Set rstCountErrors = CreateObject("ADODB.Recordset")
cnn = "Provider=SQLOLEDB.1;Password=just4now;Persist Security Info=True;User ID=tempsa;Initial Catalog=cmd_test;Data Source=ROSSQL20"
strSQL = "SELECT * FROM rpt_cmd_user_count_detail WHERE date_of_report = '" & txtInputDate.Text & "' ORDER by date_of_report, update_uid"
rstCountErrors.Open strSQL, cnn, 3 'adOpenStatic = 3
'Clear any existing values from the spreadsheet control.
SpdRecordDetail.ActiveSheet.Cells(1, 1).Select
SpdRecordDetail.ActiveSheet.UsedRange.Clear
'Add the field names as column headers.
For fldCount = 0 To rstCountErrors.Fields.Count - 1
intIRow = intIRow + 1
SpdRecordDetail.ActiveSheet.Cells(1, intIRow).Value = rstCountErrors.Fields(fldCount).Name
Next
'Fill the control with data from the database.
Dim iNumCols As Integer
Dim iNumRows As Integer
'If RS.State = adStateOpen Then RS.Close
'RS.Source = "SELECT * FROM rpt_cmd_user_count_detail WHERE date_of_report = '" & txtInputDate.Text & "' ORDER by date_of_report, update_uid"
'RS.Open
iNumCols = rstCountErrors.Fields.Count
iNumRows = rstCountErrors.RecordCount
varData = rstCountErrors.GetRows(iNumRows)
For intIRow = 1 To iNumRows
For intICol = 1 To iNumCols
SpdRecordDetail.ActiveSheet.Cells(intIRow + 1, intICol).Value = varData(intICol - 1, intIRow - 1)
Next
Next
'Format the headers in row 1 with a Bold Font that is 10 points.
With SpdRecordDetail.ActiveSheet.Range(SpdRecordDetail. Cells(1, 1), SpdRecordDetail.ActiveSheet.Cells(1, iNumCols)).Font
.Bold = True
.Size = 10
End With
'AutoFit the columns and make all text left-aligned.
With SpdRecordDetail.ActiveSheet.Range(SpdRecordDetail. Cells(1, 1), SpdRecordDetail.ActiveSheet.Cells(iNumRows + 1, iNumCols))
.AutoFitColumns
.HAlignment = ssHAlignCenter
End With
End Sub