Solved

Access VBA ADO recordset problem

Posted on 2012-03-28
5
555 Views
Last Modified: 2012-04-13
Hi,

I'm using ADO to load a dynamic recordset to a form.

It works okay except when I set the forms recordset to the recordset returned via ADO it is read-only.   I need the form fields to be editable as I'm using a SQL Server Stored proc to update the table.

Any ideas?

I've attached the code below.

Code behind form :

<code>

Public Sub LoadClient(ClientId As Integer)

If Not Me.Recordset Is Nothing Then
    Me.Recordset.CancelUpdate
End If

Dim sql As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim clDA As New ClientDA
   
   
sql = "some sql"
   
   
Set rs = clDA.GetRecordSet(sql)
Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
Set clDA = Nothing

End Sub

</code>

The clDA class is listed below :

<code>

Public Function GetRecordSet(sql As String) As ADODB.Recordset

   Dim rs As ADODB.Recordset
   
   'Create an instance of the ADO Recordset class, and
   'set its properties
   Set rs = New ADODB.Recordset
   OpenCnn
   With rs
      Set .ActiveConnection = cnn
      .Source = sql
      .LockType = adLockOptimistic
      .CursorType = adOpenKeyset
      .Open
   End With
   
   Set GetRecordSet = rs

End Function

</code>

The connection string is :

<code>

Public Const CNN_STR = "DRIVER=SQL
Server;SERVER=server;Trusted_Connection=Yes;DATABASE=database;"

Public Const CNN_PRV = "Microsoft.Access.OLEDB.10.0"
</code>

Any ideas?
0
Comment
Question by:lee_jd
5 Comments
 
LVL 11

Expert Comment

by:rajvja
ID: 37775473
Try using rs.clone

Me.Recordset = rs.clone()
0
 
LVL 77

Expert Comment

by:peter57r
ID: 37775521
Which version of Access?  From (maybe faulty) memory I think you need at least A2003 for the data to be updateable.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 37776178
see the method use from this link

How to use ADO disconnected and persisted recordsets
http://support.microsoft.com/kb/195082
0
 
LVL 2

Author Comment

by:lee_jd
ID: 37783342
I'm run Access 2010 and querying SQL Server 2008 R2.

I tried rs.clone() but it had no effect.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 37783425
did you look at the method from the link i posted ?
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now