Solved

ADO - crash when adding new record

Posted on 2000-05-05
8
155 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

813 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

10 Experts available now in Live!

Get 1:1 Help Now