My goal was export the current record of a recordset to Excel file. As written by Eric, it's impossible to set the current record to another recordset.
But copyFromRecordset has very interesting properties for solve my issue as you can see below
CopyFromRecordset RecordSet , MaxRows , MaxColumns Full description here
So I tested this code and It works great
Dim oRecSet As Recordset, oRecSetClone As Recordset
Dim varBookmark As Variant
Set objExcelApp = New Excel.Application
objExcelApp.Visible = True
Set wb = objExcelApp.Workbooks.Open("G:\Access\test.xlsx")
Set ws = wb.Sheets(1)
sSQL = "SELECT * FROM tbl"
Set oRecSet = CurrentDb.OpenRecordset(sSQL)
Set oRecSetClone = oRecSet.Clone
Do While Not oRecSet.EOF
Debug.Print i
oRecSetClone.Bookmark = oRecSet.Bookmark
ws.Range("A" & i).CopyFromRecordset oRecSetClone, 1
oRecSet.MoveNext
Loop
End Sub
Just one comment
I use bookmark because I noticed a strange behaviour when I Apply copyFromRecordSet rec,1.
After this command, rec.movenext generates an error message: Nbr 3021 - No current record