ADO - crash when adding new record

Posted on 2000-05-05
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
Question by:dsa7
LVL 14

Expert Comment

ID: 2782322
Is WINCATS.MDB write protected / Read Only ?

Expert Comment

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

Author Comment

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.
LVL 32

Expert Comment

ID: 2782441
What sort of crash?  What error is it returning?
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.


Accepted Solution

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!


Expert Comment

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.


Author Comment

ID: 2782520
Adjusted points from 50 to 75

Author Comment

ID: 2782521
That fixed it.  Thanks.

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

19 Experts available now in Live!

Get 1:1 Help Now