Re: Access Crashes with ADO Delete Record Command




I'd expect to get an error on the following line:
rst.Open SQLCodeA, db, adOpenKeyset, adLockOptimistic

but you don't

The reason I'm asking is because I don't see where intID has been given a value, so I guess you've removed that from your snippet

(Unless that's your problem)

Argusy

BTW - this is a DAO group, not an ADO group, but most of the gurus lurking just around the corner are experts in both.


jamie wrote:
To anyone who can help:

I have a form, in data*** view, I wrote code (in ADO), listed below,
to delete a given record. The code is placed in a module, and called
by simmilar forms. For this paticular form, when I initate the code,
the record is deleted and the application crashses (shuts down without
warning). The table is linked.

When I execute the command in debug mode, the following error (Record
Is Deleted, 3167) is recieved, when I press end the application ends.
When I bypass the requerry cmd, and refresh the form mannually, I get
the same error.

Thus far, I have tried to compact/repair both tables; rebuild the form,
rebuild the table. I even deleted all table relationships.

For all my attempts, I have had no luck. - Thanks in advance, to anyone
who can assit

'***** Code Snipit *****
Dim db As ADODB.Connection
Dim rst As ADODB.Recordset
Dim rst2 As ADODB.Recordset
Dim msgResult, ItemCurrent As Long
Dim lngRelatedID As Variant

'-- Constants --
SQLCodeA = "SELECT CB_MaterialProject.ID " _
& "From CB_MaterialProject " _
& "WHERE CB_MaterialProject.ID = " & intID

'-- Objects --
Set db = CurrentProject.Connection
Set rst = New ADODB.Recordset

DoCmd.close acForm, strFormName, acSaveNo 'Close form to avoid errors

'-- Open Database --
rst.Open SQLCodeA, db, adOpenKeyset, adLockOptimistic
If rst.EOF Then Exit Sub
msgResult = MsgBox("Do you wish to delete Item ?", vbInformation +
vbYesNo)
If msgResult = vbYes Then
rst.Delete (adAffectCurrent)
rst.Update
rst.close
end If

me.requery '!!!!!!!!!!!!!! Code fails here


.


Loading