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!
Many thanks
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