Solved Recordset EOF

ProgramRasta

Member
Local time
Today, 22:07
Joined
Feb 27, 2020
Messages
98
Hi All,

I have a problem with a piece of code I'm using that I was hoping someone could provide some wisdom on.

The problem is the code falls over when there is nothing to add in rsSource which can often be the case.

I can cheat with a resume next command but I was hoping for something a little less dirty!

SQL:
Public Function AddData(TableName As String, rsSource As DAO.Recordset)

Dim rsDestination As DAO.Recordset
Dim i As Long

Set dbs = CurrentDb
Set rsDestination = dbs.OpenRecordset(TableName)

    Do While Not rsSource.EOF
    
        With rsDestination
            .AddNew
                For i = 0 To rsSource.Fields.Count - 1
                    rsDestination.Fields(rsSource.Fields(i).Name) = rsSource.Fields(i).Value
                Next i
            .Update
        End With
        
        rsSource.MoveNext
        
    Loop
    
End Function

Many thanks
 
Hi. Which part of the code fails?
 
You could count the number of records in rsSource:-

Air Code:-
Code:
If rsSource.count = 0 then Exit Function
 
Thank you for replying.

The problem was with a different extract of code.

Apologies for wasting your time.
Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom