Solved

Trouble Editing an ADO Recordset bound to an Microsoft Access Form

Posted on 2016-08-08
4
43 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

757 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

18 Experts available now in Live!

Get 1:1 Help Now