SomeRandomName
SomeRandomName

Reputation: 603

EOF returns true even if i have a populated recordset at the first pos in ADO

Im trying to get rows from the columns in a recordset and then insert those in a table plain and simple.

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 have a similar function woorking but this one won't woork for some reason.

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

current Code ~

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

It jumps out at Do While Not rsData.EOF..

Upvotes: 3

Views: 6046

Answers (2)

HansUp
HansUp

Reputation: 97131

GetString leaves the recordset at EOF. MoveFirst again before Do While Not rsData.EOF

rsData.MoveFirst
MsgBox rsData.GetString
rsData.MoveFirst ' <-- add this
'Manipulate each row of the result column.
Do While Not rsData.EOF

Upvotes: 3

Trace
Trace

Reputation: 18889

I didn't try your code, but this logically means that the recordset is empty. Check carefully if the query you executed on the db is correct.

In Access, use DAO instead of ADO and try this:

Set db = CurrentDb
set rsData = db.OpenRecordset("SELECT Forhandler, Selger FROM data", dbOpenDynaset) 

Upvotes: 0

Related Questions