?
Solved

ADO - crash when adding new record

Posted on 2000-05-05
8
Medium Priority
?
161 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

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

Accepted Solution

by:
MTroutwine earned 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 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