Making read-only recordset updatable


I'm looking for a way to change a read-only recordset into an updateable one.

The application queries several tables and, due to the links, returns a non-updateable result.

I then disconnect this (ActiveConnection=Null) and want to edit the results for a report, but I can't see a way of changing the results table.

I've tried saving it as a persisted recordset and reopening as editable, but it still remembers that it cannot be updated.

Anyone any clues?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are these updates temporary???

If not, why not do the updates directly on the table that needs to be updated using the connection object
yourconn.execute "update table set yourfield = NewData where tablekey = " & localrs.fields("key")

then set the local recordsets connection back and refresh it.

StuckInTheMudAuthor Commented:
Yes, they are temporary for the report. I specifically don't want to change underlying data.

Why would you like to only "temporarily" change the data??

What db is this?  Access??  You could always look into using temporary tables turn the queries into insert statements and then modify the temp tables and run your reports off of these tables.  Although this isn't very "clean".

Perhaps you could make the changes in the query itself??  If these are calculations, that would be quite easy to do.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

StuckInTheMudAuthor Commented:
DB is Oracle and SQL Server (I have a couple of apps I want to do this in).

I'm using the recordset as a grid for a report that is displayed/exported to excel. The changes are things like removing specific text for display grouping.

Anyway, this is irrelevant to the original query, how to make a read-only recordset into an editable one.
Try using a disconnected recordset:

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.Open ""Provider=sqloledb;Data Source=YourServer;Initial Catalog=YourDb;User Id=;Password=;"
rs.CursorLocation = adUseClient
rs.LockType = adLockBatchOptimistic
rs.Open "SELECT Table1.Test, Table2.test1 FROM Table1 JOIN table2 ON Table1.Pkey = Table2.Pkey;", conn
Set rs.ActiveConnection = Nothing
rs.fields(1) = "Mike "

I opened the above and it's originally not updatable, but once it was disconnected, I was able to make modifications.
Okay I just re-read your original question and you already tried a disconnected recordset?!?!

Perhaps your locktype was wrong??
>how to make a read-only recordset into an editable one.

You can not.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
if u wan to edit data,then do not open ur recordset as read-only...
really simple logic and concept...
have fun...
make a copy of the original recordset using

  Set rs2 = CopyRecordset(rs)

rs2 will be updateable.

Public Function CopyRecordset(ByRef rs As Recordset) As Recordset
    Dim fld As ADODB.Field
    Dim rsDummy As New Recordset ' the resulting recordset
    ' create fields in rsDummy
    For Each fld In rs.Fields
        rsDummy.Fields.Append fld.Name, fld.Type, fld.DefinedSize, fld.Attributes
    ' copy the recordset's content
    While Not rs.EOF
        For Each fld In rs.Fields
            rsDummy.Fields(fld.Name) = rs.Fields(fld.Name)
    Set CopyRecordset = rsDummy
    Exit Function
End Function
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.