Solved Recordset EOF (1 Viewer)

ProgramRasta

Member
Local time
Today, 14:38
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:38
Joined
Oct 29, 2018
Messages
21,358
Hi. Which part of the code fails?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:38
Joined
Jul 9, 2003
Messages
16,245
You could count the number of records in rsSource:-

Air Code:-
Code:
If rsSource.count = 0 then Exit Function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:38
Joined
Oct 29, 2018
Messages
21,358
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

Top Bottom