Click here to Skip to main content
15,177,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to get rows from 2 columns in a recordset and then inser those in a table.

The recordset is populated and i used .MoveFirst to start at the beginning of the rs, Still i get EOF true at the very start and it jumps out of the do while..

I can't figureout why... or how to fix this. Anny insight is welcome!


current Code ~
VB
Public Function makeSäljare()
    'Create rs
    Dim rsData As ADODB.Recordset
    Set rsData = New ADODB.Recordset
    Dim sql As String
    
    'Select what should be included in the rs.
    rsData.Open "SELECT Forhandler, Selger FROM data", _
    CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    rsData.MoveFirst
    
    
    MsgBox rsData.GetString
        
    'Manipulate each row of the result column.
    Do While Not rsData.EOF
        

        sql = "INSERT INTO säljare (Partner_Namn, Namn ) VALUES ('" & rsData!forhandler & "','" & rsData!Selger & "');"
        MsgBox sql
        'DoCmd.SetWarnings (False)
        DoCmd.RunSQL (sql)
        'DoCmd.SetWarnings (True)
        
        
        rsData.MoveNext
        'If rsData.EOF Then Exit Do
        
    Loop
    
    rsData.Close
    
End Function
Posted
Updated 11-Sep-13 10:41am
v2
Comments
[no name] 11-Sep-13 15:49pm
   
Try doing a MoveLast before MoveFirst. I don't know if that will help or not.

I was using the .getString method _after_ i used .MoveFirst leading to the .getString method moving the rs to EOF and not looping trough the rs because of it!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900