Public Function DeleteRecord()
'This function permits record deletions when the user explicity requests a
'delete via the DeleteRecord menu item.
On Error GoTo ErrorHandler
Const strProcedureName = "DeleteRecord"
Dim frm As Form
'Make sure there is an active form.
On Error Resume Next
Set frm = Screen.ActiveForm
If Err.Number <> 0 Then
GoTo ExitRoutine
End If
On Error GoTo ErrorHandler
'If form has no RecordSource, no need to continue.
If Format$(frm.RecordSource) = "" Then
GoTo ExitRoutine
End If
'If this is a new record, no need to continue.
If frm.NewRecord Then
GoTo ExitRoutine
End If
'All if well, so do what we came here to do.
gstrActiveFormForDeleteRecord = frm.Name
'Send F2 to ensure that the user has not selected all records.
SendKeys "{F2}", True
'Select the current record (and ensure only one is selected!)
On Error Resume Next
RunCommand acCmdSelectRecord
If Err.Number <> 0 Then
GoTo ExitRoutine
End If
On Error GoTo ErrorHandler
'Do the regular "Delete Record" menu option.
'On Error Resume Next
If frm.Dirty = True Then
frm.Undo
End If
DoCmd.RunCommand acCmdDeleteRecord
'SendKeys "{DELETE}", True
gobjLastError.Save Err, strProcedureName
On Error GoTo ErrorHandler
Select Case gobjLastError.Number
Case 0 'No error
'Do nothing
Case Else
'Give a system error for anything else.
gobjLastError.Raise gobjLastError.Number & ": " & gobjLastError.Description
End Select
ExitRoutine:
On Error Resume Next
gstrActiveFormForDeleteRecord = ""
Exit Function
ErrorHandler:
gobjLastError.Save Err, strProcedureName
Select Case gobjLastError.Number
Case Else
gobjLastError.Show
Resume ExitRoutine
End Select
End Function
|