Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Access VBA ADO recordset problem

Posted on 2012-03-28
5
Medium Priority
?
613 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
[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
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 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 120

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

647 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