Linked Table Loop

clive2002

Registered User.
Local time
Today, 21:35
Joined
Apr 21, 2002
Messages
91
Since splitting my db i'm having problems looping through recordsets, i think it's something to do with the movenext or possibly the calculation of the recordCount as i'm only looping to the first record.

Any help much appreciated, code below.


Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblMyTable")

If Not rst.EOF Then
For i = 1 To rst.RecordCount

other code here

rst.MoveNext
Next i
End If
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
 
Code:
    Set dbs = CurrentDb 
    Set rst = dbs.OpenRecordset("tblMyTable") 

    Do While Not rst.EOF Then 
        other code here 
        rst.MoveNext 
    Loop

    rst.Close 
    dbs.Close 
    Set rst = Nothing 
    Set dbs = Nothing


or:

Code:
    Dim i As Integer
    Set dbs = CurrentDb 
    Set rst = dbs.OpenRecordset("tblMyTable") 

    rst.MoveLast
    rst.MoveFirst
    For i = 1 To rst.RecordCount 
        other code here 
        rst.MoveNext 
    Next i

    rst.Close 
    dbs.Close 
    Set rst = Nothing 
    Set dbs = Nothing
 
Thanks,

Works a treat!
 

Users who are viewing this thread

Back
Top Bottom