Gasman
Enthusiastic Amateur
- Local time
 - Today, 06:44
 
- Joined
 - Sep 21, 2011
 
- Messages
 - 17,412
 
Hi all,
As an intellectual exercise, I decided to see if I could solve this question with a recordset as I had originally suggested.
https://www.access-programmers.co.uk/forums/threads/fill-table-control.315132/page-2#post-1735501
I imported the Excel sheet into a table called LTSB and created the code below.
The code works as far as it updates the rows correctly, but errors with No current record - 3021 as I have reached EOF on the inner loop, but I cannot see why the test fails for EOF.?
I even tried Do While NOT rs.EOF and rs![Interval ID 1] <>"O", but still get No current record.?
So where is my logic failing please.?
The ID field is just there so I could use in a Watch window.
TIA
	
	
	
		
 As an intellectual exercise, I decided to see if I could solve this question with a recordset as I had originally suggested.
https://www.access-programmers.co.uk/forums/threads/fill-table-control.315132/page-2#post-1735501
I imported the Excel sheet into a table called LTSB and created the code below.
The code works as far as it updates the rows correctly, but errors with No current record - 3021 as I have reached EOF on the inner loop, but I cannot see why the test fails for EOF.?
I even tried Do While NOT rs.EOF and rs![Interval ID 1] <>"O", but still get No current record.?
So where is my logic failing please.?
The ID field is just there so I could use in a Watch window.
TIA
		Code:
	
	
	Sub CopyHeader()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String, strHeader As String
Dim iModified As Integer
strSQL = "Select ID, Field7, [Description 1], [Interval ID 1] FROM LTB"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL)
Do Until rs.EOF
    strHeader = rs![Description 1]
    rs.Edit
    rs!Field7 = strHeader
    rs.Update
    iModified = iModified + 1
    rs.MoveNext
    Do Until rs.EOF Or rs![Interval ID 1] = "O"
        rs.Edit
        rs!Field7 = strHeader
        rs.Update
        iModified = iModified + 1
        rs.MoveNext
    Loop
        
Loop
rs.Close
MsgBox "Number of records updated was " & iModified
Set rs = Nothing
Set db = Nothing
End Sub