I need help with the following code. The code is pulling records from table "Questions" and looping through the columns labeled "Questions #1" - #10. It works fine but only for the first ID number, I get an item not found error once it reaches the last column ("Question #10") for the first ID number, so basically my loop is not moving to the next ID number.
Code:
Option Compare Database
Option Explicit
Sub SomeProcedure()
Dim db As DAO.Database, recIn As DAO.Recordset, recOut As DAO.Recordset, i As Integer
Set db = CurrentDb()
Set recIn = db.OpenRecordset("Questions", dbOpenDynaset, dbReadOnly)
Set recOut = db.OpenRecordset("Questions2", dbOpenDynaset, dbEditAdd)
With recIn
.MoveFirst
Do
For i = 0 To .Fields.Count
If Left(.Fields(i).Name, 8) = "Question" Then
recOut.AddNew
recOut.Fields("Loan Number") = recIn.Fields("Loan Number")
recOut.Fields("Total Questions") = recIn.Fields(i)
recOut.Update
End If
Next i
.MoveNext
Loop Until .EOF
End With
recIn.Close
recOut.Close
db.Close
End Sub
Comment