Solved

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

Posted on 2016-11-21
4
85 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 85

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

623 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