Question : VBA ADO:  .GetString method causes .MoveNext method to fire - anyone know why?

Working with Access VBA, I have a routine to open a table, process the records, and then write each record to a new table.  Before processing the record, I check to see if a record with the key field from the SOURCE table already exists on the DESTINATION table.  A simple check for duplicates.  If there is a duplicate, I pass the record to a function to write it out to a text file.  I pass the record to the error function by loading a record into a string variable using the ADO .GetString method.  

The problem is this:  the .GetString method is moving the cursor forward in my recordset.  Nowhere in any documentation have I seen anything that would cause me to expect this behaviour.  This causes a record on the SOURCE file to be skipped because my loop uses the .MoveNext method to loop through the SOURCE file.  Therefore, after every duplicate record found I lose the next record on the source file because it is never evaluated.

I suppose one alternative is to use the .MovePrevious method immediate after the .GetString but this seems clumsy.  Any ideas?  Any supporting documentation to explain this?  Please help!

Thank you,
Pete

Here is a portion of the code:

    rstBatch.Open "[Batch_Data]", CurrentProject.Connection, adOpenStatic
     
    'make sure there are records in the batch table
    If rstBatch.BOF And rstBatch.EOF Then
        MsgBox "Import Table is empty!", vbOKOnly, "No records to Process!"
        Exit Function
    End If
   
    With rstBatch
        .MoveLast
        .MoveFirst
       
        For iRec = 1 To rstBatch.RecordCount
       
            'is the record already in the table?
            strKeyChk = rstBatch.Fields("ForeignKey")
            intRecExists = DCount("PM_Key", "tblPAD", "[PM_ Key] = '" & strKeyChk & "'")
            If intRecExists > 0 Then
                strErr_Rec = rstBatch.GetString(, 0)   <----***** recordset moves forward here, why?
                Write_Import_Err_Rec_to_Text_File strErr_Rec
                sMsgResp = MsgBox("Record already exists in Table!", vbOKCancel, "Table Write Error")
                If sMsgResp = vbCancel Then GoTo Exit_Batch_Chk
                GoTo Next_i_Rec
            End If
                                         
            'Process batch record here
            Process_Batch_Sub_Routine
     
Next_i_Rec:
           
            ' Continue with next record
            .MoveNext  <----***** I expected the recordset to only advance here
        Next iRec
       
       
    End With

Answer : VBA ADO:  .GetString method causes .MoveNext method to fire - anyone know why?

I'm not really familiar with the GetString method but I guess that since it's returning the recordset as a string, it must read the recordset by moving forward...

To compensate you could use :

rstBatch.MovePrevious

just after the GetString method
Random Solutions  
 
programming4us programming4us