Solved

Trouble Editing an ADO Recordset bound to an Microsoft Access Form

Posted on 2016-08-08
4
62 Views
Last Modified: 2016-09-03
I'm new to using ADO to open recordsets and use them with Access forms.  I typically use queries as the recordsets.  I'm trying to make the move away from that and this is my first attempt.  I'm able to bind the recordset, but can't edit any of the data once available on the form.  It's all locked.  What am I doing wrong?  

Thanks!

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Err

   Dim cn As ADODB.Connection
   Dim rs As ADODB.Recordset
   
   Set cn = New ADODB.Connection
   
   With cn
     
      .Provider = "sqloledb"
         
      .ConnectionString = "DRIVER=ODBC DRIVER 11 FOR SQL SERVER;SERVER=**;DATABASE=**;UID=**;PWD=**"
     
      .CursorLocation = adUseServer
     
      .Open
   
   End With
   
   Set rs = New ADODB.Recordset
   
   With rs
     
      .Source = "SELECT * FROM GLOBAL_CONTACTS WHERE CONTACTID = " & [Forms]![DD_GLOBAL]![GLOBAL_CONTACTID]
     
      .ActiveConnection = cn
     
      .CursorType = adOpenKeyset
     
      .LockType = adLockOptimistic
     
      .Open
   
   End With
   
   Set Me.Recordset = rs
   
Form_Open_Exit:
    Exit Sub

Form_Open_Err:
    MsgBox ""
    Resume Form_Open_Exit
0
Comment
Question by:tommyboy115
  • 2
  • 2
4 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 41748391
What version of Access?   It's probably the provider.   You need to use the Access OLEDB provider:

https://support.microsoft.com/en-us/kb/281998

Jim.
0
 

Author Comment

by:tommyboy115
ID: 41748885
I'm using Access 2016 and SQL Server 2014
0
 

Author Comment

by:tommyboy115
ID: 41748988
Thanks Jim!  That reference worked!  If I want to create a new record instead of looking up an existing one, how should I change my code?  Scold me if I should be asking that in a new question.  Thanks!
0
 
LVL 57
ID: 41749083
<< If I want to create a new record instead of looking up an existing one, how should I change my code?  >>

 You'd create an empty recordset and let the form add the record.   best way to do that is include a WHERE clause of:

 WHERE 1 = 0

Jim.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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