?
Solved

Making read-only recordset updatable

Posted on 2006-04-11
11
Medium Priority
?
357 Views
Last Modified: 2013-12-25
Hi,

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?


Thanks!


Jim
0
Comment
Question by:StuckInTheMud
9 Comments
 
LVL 11

Expert Comment

by:leclairm
ID: 16428814
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.



0
 

Author Comment

by:StuckInTheMud
ID: 16434629
Yes, they are temporary for the report. I specifically don't want to change underlying data.


Jim
0
 
LVL 11

Expert Comment

by:leclairm
ID: 16435367
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:StuckInTheMud
ID: 16435455
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.
0
 
LVL 11

Expert Comment

by:leclairm
ID: 16435573
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.
0
 
LVL 11

Expert Comment

by:leclairm
ID: 16435585
Okay I just re-read your original question and you already tried a disconnected recordset?!?!

Perhaps your locktype was wrong??
0
 
LVL 29

Accepted Solution

by:
leonstryker earned 1000 total points
ID: 16435908
>how to make a read-only recordset into an editable one.

You can not.
0
 
LVL 8

Expert Comment

by:MYLim
ID: 16748599
if u wan to edit data,then do not open ur recordset as read-only...
really simple logic and concept...
have fun...
0
 
LVL 1

Expert Comment

by:infogaters
ID: 17303162
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
    Next
   
    rsDummy.Open
   
    ' copy the recordset's content
    While Not rs.EOF
        rsDummy.AddNew
        For Each fld In rs.Fields
            rsDummy.Fields(fld.Name) = rs.Fields(fld.Name)
        Next
        rsDummy.Update
        rs.MoveNext
    Wend
   
    Set CopyRecordset = rsDummy
    Exit Function
End Function
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

750 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