Solved

Trouble Editing an ADO Recordset bound to an Microsoft Access Form

Posted on 2016-08-08
4
94 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
[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
  • 2
  • 2
4 Comments
 
LVL 58

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 58
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

707 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