Need language for Delete Record? warning

S

Sheila

I want to add a warning to a Delete Record, with the choices of Yes and
Cancel. I'm just not getting the language correct. Assistance would be
appreciated.
 
K

Ken Sheridan

Put something like this in the form's Delete event procedure:

Const conMESSAGE = _
"Are you sure you wish to delete this record."

If MsgBox(conMESSAGE, vbOKCancel + vbQuestion, "Delete Record") _
= vbCancel Then
Cancel = True
End If

and this in its BeforeDelConfirm procedure:

Response = acDeleteOK

If you have added a button to the form for deleting the current record
rather than simply relying on the standard toolbar, menu or keyboard methods.
you'll need to handle the error which will arise on cancellation, with code
like this in the button's Click event procedure:

Const DELETECANCELLED = 2501

On Error Resume Next
RunCommand acCmdDeleteRecord
Select Case Err.Number
Case 0
' no error
Case DELETECANCELLED
' anticipated error
' so do nothing
Case Else
' unknown error
' so inform user
MsgBox Err.Descriptiom, vbExclamation, "Error"
End Select

Ken Sheridan
Stafford, England
 
S

Sheila

Ken:
I'll give it a try. It's good to know I was on the correct path.
Thank you.
Sheila
 
J

John W. Vinson

I'm getting an "Invaild Outside Procedure" on (conMESSAGE)

Where are you putting the code? It should be *between* the Private Sub
Form_Delete(Cancel as Integer) and End Sub lines.

Note also that the newsgroup post has word wrap which you will need to
correct.
 
S

Sheila

This is what I have (in a module):


Private Sub Delete_Current_Record_Click()

Const conMESSAGE = _
"Are you sure you wish to delete this record."

If MsgBox(conMESSAGE, vbOKCancel + vbQuestion, "Delete Record") _
= vbCancel Then
Cancel = True
End If

'Delete Confirm procedure:

Response = acDeleteOK

'Delete Cancelled Error Procedure

Const DELETECANCELLED = 2501

On Error Resume Next
RunCommand acCmdDeleteRecord
Select Case Err.Number
Case 0
' no error
Case DELETECANCELLED
' anticipated error
' so do nothing
Case Else
' unknown error
' so inform user
MsgBox Err.Descriptiom, vbExclamation, "Error"
End Select

End Sub
 
J

John W. Vinson

This is what I have (in a module):


Private Sub Delete_Current_Record_Click()

Const conMESSAGE = _
"Are you sure you wish to delete this record."

If MsgBox(conMESSAGE, vbOKCancel + vbQuestion, "Delete Record") _
= vbCancel Then
Cancel = True
End If

'Delete Confirm procedure:

You have a comment line for Delete Confirm but does the Form's On Delete event
have [Event Procedure] in it? Do you have a line in the code like

Private Sub Form_Delete(Cancel as Integer)

As it is, it's not clear what the context for the following code might be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top