Solved

ADO - crash when adding new record

Posted on 2000-05-05
8
153 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
 
LVL 32

Expert Comment

by:bhess1
ID: 2782441
What sort of crash?  What error is it returning?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…

911 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

17 Experts available now in Live!

Get 1:1 Help Now