I am using two recordsets for inputting data into an access table. I have used two loops for each recordset to do so. My intent is to read data into the table from an Excelsheet. My first recordset selects all columns from the excelsheet and does what it is supposed to do. The second recordset selects only a handful of columns from the Excelsheet, but when using the second recordset I am only able to get the first row of data transferred into the table and not able to get all rows of data in. The second recordset starts from column number 30 and field number 27 in the table. The format of the first Recordset is very similar the only difference being that the 1st one uses cStartColumn1 as input in the function argument inside the for loop and the second one uses iCol which indicates the location of current column to which the cursor is pointing to. I will include the code for the second recordset here:
Code:
Dim rs2 As DAO.Recordset
Dim strSQL As String
Dim iColumn As Integer
Dim iField As Integer
Dim lrecords1 As Long
iCol = iCol + 2 'increments the column from 28 which is where the first recordset was stopped to 30 which is the starting column for the second.
strSQL = "SELECT [Field Measurement (m)],[Line Completed?], [Major Defects(codes only)],[CCTV Inspection Comments], [Date] FROM " & sTable
Set rs2 = dbs.OpenRecordset(strSQL)
With rs2
.AddNew
End With
iRow = cStartRow1
iColumn = iCol
Do While Not wks.Cells(iRow, 30) = ""
cStartField1 = rs2.Fields(0)
iField = cStartField1
lrecords1 = lrecords1 + 1 'this is the line where I am supposed to see the records incremented in the access table.
For iColumn = iCol To iCol + (rs2.Fields.Count - (cStartField1 + 1))
rs2.Fields(iField) = wks.Cells(iRow, iColumn)
DoCmd.Hourglass True
iField = iField + 1
If iField = 5 Then
rs2("Date").value = wks.Cells(3, 3)
End If
Next
iRow = iRow + 1
rs2.Update
rs2.AddNew
loop
rs2.Close
Set rs2 = Nothing
Comment