Solved

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

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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