Solved

Changing the Source of an ADO Recordset while it's open

Posted on 2016-11-21
4
25 Views
Last Modified: 2016-11-30
I want to re-use an ADO recordset (same object variable to reference it, same Active Connection, Locktype, and cursortype properties, etc.)  I just want to change the source.  Can the source of an ADO Recordset be changed while it's open or do I have to close it first, change the source, and then re-open it?

Also,  if I need to only reference and update one record at a time, should I re-open the recordset with a source that has a different where clause each time I need to change another record or should I use the filter property?  I'm thinking that it's better to re-open the recordset so the source contains only one record (the one I need to update) as opposed to it containing thousands of records and then filtering it to get the record I need to update.
0
Comment
Question by:Declan_Basile
  • 2
4 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 41896740
Is this VBA or VB.NET? If the latter, why are you using RecordSets?
0
 
LVL 1

Author Comment

by:Declan_Basile
ID: 41897523
This is VBA.  However, I'm also asking for when I eventually write more programs in VB.NET.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 41898894
You would Close and then Open the recordset again, but you'd need to specify your Cursor, Lock etc again, just as you did originally.

If you're updating based on data in that recordset just use an SQL UPDATE statement:

Dim sql as String
sql = "UPDATE SomeTable SET SomeField=" & rst("Field1") & " WHERE YourIDValue=" & rst("IDField")
YourConnection.Execute sql
0
 
LVL 1

Author Comment

by:Declan_Basile
ID: 41899587
Every time there is user input, I need not only to write data but also read data from a specific record.  Each time there's user intput, should I re-open the recordset with a different Where clause, open the recordset once without any filter or where clause and find the record, or change the recordset's filter property?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now