Solved

ADO - crash when adding new record

Posted on 2000-05-05
8
156 Views
Last Modified: 2010-05-02
The following code crashes when it hits the line rsLetters.AddNew.  Can anyone tell me why this crashes?  Everything looks okay to me.

Dim rsLetters As New ADODB.Recordset
Dim cnLetters As New ADODB.Connection

cnLetters.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\WINCATS.mdb;Persist Security Info=False"

rsLetters.CursorType = adOpenKeyset
rsLetters.Source = "Letter"
rsLetters.Open , cnLetters
cnLetters.BeginTrans
   
rsLetters.AddNew
0
Comment
Question by:dsa7
8 Comments
 
LVL 14

Expert Comment

by:wsh2
ID: 2782322
Is WINCATS.MDB write protected / Read Only ?
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2782341
Check your "rs.open" statement.  Looks like you're opening it wrong (I'd have to see your database to confirm).
0
 

Author Comment

by:dsa7
ID: 2782435
wincats.mdb is not write protected.

I also tried

rsLetters.Open "select * from letter", cnLetters, adOpenKeyset

and that did not work either.  It seems like it should be something obvious but I cannot figure it out.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 32

Expert Comment

by:bhess1
ID: 2782441
What sort of crash?  What error is it returning?
0
 
LVL 3

Accepted Solution

by:
MTroutwine earned 75 total points
ID: 2782507
I believe what you want to do is add this line after your cursor type:

rsLetters.LockType = adLockOptimistic

The default LockType is ReadOnly and will not permit you to add, update or delete records!

:>)
0
 
LVL 3

Expert Comment

by:MTroutwine
ID: 2782516
One thing I failed to mention.  You don't necessarily have to lock the recordset as adLockOptimistic you can use adLockPessimistic as well here is the MSDN description for both (much better than if I explained the difference).

adLockPessimistic: Pessimistic locking, record by record—the provider does what is necessary to ensure successful editing of the records, usually by locking records at the data source immediately upon editing.

adLockOptimistic: Optimistic locking, record by record—the provider uses optimistic locking, locking records only when you call the Update method.

:>)
0
 

Author Comment

by:dsa7
ID: 2782520
Adjusted points from 50 to 75
0
 

Author Comment

by:dsa7
ID: 2782521
That fixed it.  Thanks.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

839 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