How to Loop thru DAO recordset connected to ODBC database

steveapa

New Member
Joined
Jan 15, 2014
Messages
7
Hi.

How do I loop thru the recordset? rsRDO.movenext works, but rsRDO.movelast, first, previous does not work. Excerpts below

Code:
Dim wsEngine As DAO.Workspace
Dim dbConnect As DAO.Database
Dim rsRDO As DAO.Recordset

Set wsEngine = CreateWorkspace("ODBCWorkspace", "[User Name]", "[Password]", dbUseODBC)
Set dbConnect = wsEngine.OpenDatabase("[Name]", , , connectstr)
Set rsRDO = dbConnect.OpenRecordset(sqlstr)
rsRDO.movenext
'do stuff
rsRDO.movefirst
The query runs properly. rsRDO.movenext works properly, but how do I go back in the recordset? I need to loop thru the recordset, looking for something, then go back to the beginning and look for the next something.

When I try rsRDO.movefirst, I get error# 3219

Thanks.
Steve
Harrisburg, PA
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
SOLVED: Problem was how I opened the recordset. It should have been:
Set rsRDO = dbConnect.OpenRecordset(sqlstr, dbOpenDynaset) ' to read and edit, move forward and back
or
Set rsRDO = dbConnect.OpenRecordset(sqlstr, dbOpenSnapshot) ' to only read forward and back, no edit
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top