Jon von der Heyden
MrExcel MVP, Moderator
- Joined
- Apr 6, 2004
- Messages
- 10,907
- Office Version
- 365
- Platform
- Windows
Hi
I am getting an error attempting to load and array from a recordset... This is slimmed down version, initially populating recordset with array but then eventually want to write it back out to an array too...
Error Msg: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
How can I make this spit out an array again?
Edit: recData.MoveFirst doesn't seem to do the trick either
I am getting an error attempting to load and array from a recordset... This is slimmed down version, initially populating recordset with array but then eventually want to write it back out to an array too...
Code:
[COLOR=blue]Public[/COLOR] [COLOR=blue]Sub[/COLOR] phoo1()
[COLOR=blue]Dim[/COLOR] arr()
[COLOR=blue]Dim[/COLOR] lngArrItem [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR]
[COLOR=blue]Dim[/COLOR] recData [COLOR=blue]As[/COLOR] ADODB.Recordset
[COLOR=blue]Dim[/COLOR] pvc [COLOR=blue]As[/COLOR] PivotCache
[COLOR=blue]Set[/COLOR] recData = [COLOR=blue]New[/COLOR] ADODB.Recordset
arr = [COLOR=blue]Array[/COLOR]("V", "Z", "O", "W", "N", "J", "W", "X", "V", "O", "L")
recData.Fields.Append "Field1", adVariant
recData.Open
[COLOR=blue]For[/COLOR] lngArrItem = [COLOR=blue]LBound[/COLOR](arr) [COLOR=blue]To[/COLOR] [COLOR=blue]UBound[/COLOR](arr)
recData.AddNew
recData!Field1 = arr(lngArrItem)
recData.Update
[COLOR=blue]Next[/COLOR] lngArrItem
[COLOR=blue]Debug.Print[/COLOR] "records:" & recData.RecordCount, "array items:" & [COLOR=blue]UBound[/COLOR](arr) + 1
[COLOR=blue]Set[/COLOR] pvc = ThisWorkbook.PivotCaches.Add(xlExternal)
[COLOR=blue]Set[/COLOR] pvc.Recordset = recData
pvc.CreatePivotTable Range("A40")
arr = recData.GetRows [COLOR=darkgreen]'error here[/COLOR] [COLOR=red]********[/COLOR]
[COLOR=blue]Set[/COLOR] recData = [COLOR=blue]Nothing[/COLOR]
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
Error Msg: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
How can I make this spit out an array again?
Edit: recData.MoveFirst doesn't seem to do the trick either
Last edited: