Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-11-21
4
Medium Priority
?
107 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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

916 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