Solved

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

Posted on 2016-11-21
4
36 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 75

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

912 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

22 Experts available now in Live!

Get 1:1 Help Now