Hi, I have a problem in my application ...
Need to loop throug the records in a Qry, which has 20 fields (columns), named Names, f1 ....f19 ...
It has to find fields with data and put it in a separate table ...
My code is:
Code:
Private Sub MakeApps()
Dim fldName As String
Set db = CurrentDb
Set Rec2 = db.TableDefs("newTable").OpenRecordset
Set Rec1 = db.QueryDefs("qryTest").OpenRecordset
Rec1.MoveFirst
Do Until Rec1.EOF
For I = 1 To 19
fldName = "Rec1!F" & Trim$(Str(I))
' (or fldName = "F" & Trim$(Str(I))
' If Not IsNull(Rec1!fldName) Then
If Not IsNull(fldName) Then
Rec2.AddNew
' (code goes here ...)
Rec2.Update
End If
Next
Rec1.MoveNext
Loop
Rec1.Close
Rec2.Close
db.Close
End Sub
I am using a query as a rst (Rec1) because the I have to combine data from 2 tables (at the moment).
Obviously, I cannot address the fields by name as described above. Can someone suggest another method of looping? of course I can write a lot of code usinf Ifs, and ElseIfs ... but it I am sure it can be done better.