0
votes

I'm using MS Access VBA to import from an iSeries table. Sometimes the IBM table can be empty, which is ok. However, when this occurs I receive VBA error 3021 - do I need to change my code or can I just suppress the error message. Here is my code:

Set rs = New ADODB.Recordset
rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic

'Open recordset to local table
Set rsL = New ADODB.Recordset
rsL.Open sTBL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic

rs.MoveFirst
Debug.Print "AS400"
Do Until rs.EOF
  Debug.Print rs.Fields("DROP"), rs.Fields("STDATE"), rs.Fields("ENDATE")
  rsL.AddNew
  rsL.Fields("DROP") = rs.Fields("DROP")
  rsL.Fields("STDATE") = rs.Fields("STDATE")
    rsL.Fields("ENDATE") = rs.Fields("ENDATE")
  rsL.Update
  rs.MoveNext
Loop

'Test to check if above code actually worked
rsL.MoveFirst
Debug.Print "Local"
Do Until rsL.EOF
  Debug.Print rsL.Fields("DROP"), rsL.Fields("STDATE"), rsL.Fields("ENDATE")
  rsL.MoveNext
Loop

'Clear memory
Set rs = Nothing
Set rsL = Nothing
Set cn = Nothing
2

2 Answers

0
votes

Solved it - just changed the code to the below:

'rs.MoveFirst
Debug.Print "AS400"
Do Until rs.EOF
rs.MoveFirst
0
votes

Before you use the rsL.MoveFirst you need to check to see if the recordset is empty. If rsL.RecordCount <> 0 then rsL.MoveFirst End If