G
Guest
Using KeyPreview I am intercepting the user when he/she keys Delete (KeyCode
46) and running some code to enumerate the records in the dynaset in which
the records are being deleted. I have to enumerate the records before Access
removes & buffers them during the BeforeDelConfirm event.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'intercept delete key and enumerate records first
Select Case KeyCode
Case 46
'If KeyCode is Delete
x = DeleteSelectedItems(Form_sfdtls)
End Select
End Sub
'KB Article 208502
Function DeleteSelectedItems(f As Form)
Dim i As Long
Dim RS As Object
Dim Criteria As String
' Get the form and its recordset.
Set RS = f.RecordsetClone
If RS.RecordCount = 0 Then
Set RS = Nothing
Exit Function
End If
' Move to the first record in the recordset.
RS.MoveFirst
'Move to the first selected record.
RS.Move f.SelTop - 1
' Build the string
For i = 1 To f.SelHeight
If Criteria <> "" Then
Criteria = Criteria & " OR "
End If
Criteria = Criteria & "[itemid]=" & RS.itemid
RS.MoveNext
Next i
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE items SET items.[free] = True WHERE " &
Criteria, 0
DoCmd.SetWarnings True
Set RS = Nothing
End Function
Trouble I'm having is this. Access displays the following message once when
the delete key is pressed having just added a record to the dynaset...
"The Microsoft Jet databse engine has stopped the process because you and
another user are attempting to change the same data at the same time."
When I ok the message and attempt to press delete again the code works and
intended and no message is displayed.
Can anyone show me how to prevent the message from displaying in the first
instance. TIA Simon
46) and running some code to enumerate the records in the dynaset in which
the records are being deleted. I have to enumerate the records before Access
removes & buffers them during the BeforeDelConfirm event.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'intercept delete key and enumerate records first
Select Case KeyCode
Case 46
'If KeyCode is Delete
x = DeleteSelectedItems(Form_sfdtls)
End Select
End Sub
'KB Article 208502
Function DeleteSelectedItems(f As Form)
Dim i As Long
Dim RS As Object
Dim Criteria As String
' Get the form and its recordset.
Set RS = f.RecordsetClone
If RS.RecordCount = 0 Then
Set RS = Nothing
Exit Function
End If
' Move to the first record in the recordset.
RS.MoveFirst
'Move to the first selected record.
RS.Move f.SelTop - 1
' Build the string
For i = 1 To f.SelHeight
If Criteria <> "" Then
Criteria = Criteria & " OR "
End If
Criteria = Criteria & "[itemid]=" & RS.itemid
RS.MoveNext
Next i
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE items SET items.[free] = True WHERE " &
Criteria, 0
DoCmd.SetWarnings True
Set RS = Nothing
End Function
Trouble I'm having is this. Access displays the following message once when
the delete key is pressed having just added a record to the dynaset...
"The Microsoft Jet databse engine has stopped the process because you and
another user are attempting to change the same data at the same time."
When I ok the message and attempt to press delete again the code works and
intended and no message is displayed.
Can anyone show me how to prevent the message from displaying in the first
instance. TIA Simon