ADO - crash when adding new record

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
dsa7Asked:
Who is Participating?
 
MTroutwineConnect With a Mentor Commented:
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
 
wsh2Commented:
Is WINCATS.MDB write protected / Read Only ?
0
 
GivenRandyCommented:
Check your "rs.open" statement.  Looks like you're opening it wrong (I'd have to see your database to confirm).
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
dsa7Author Commented:
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
 
Brendt HessSenior DBACommented:
What sort of crash?  What error is it returning?
0
 
MTroutwineCommented:
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
 
dsa7Author Commented:
Adjusted points from 50 to 75
0
 
dsa7Author Commented:
That fixed it.  Thanks.
0
All Courses

From novice to tech pro — start learning today.