Changing Access Default Message

Zippyfrog

Registered User.
Local time
Today, 03:45
Joined
Jun 24, 2003
Messages
103
Right now I have a button on a form that deletes a record, and when I click on the button to delete, the default access message comes up saying, "You are about to delete 1 records. If you click yes, you won't be able to undo the delete operation..." and when I click no, it says "The DoMenuItem action was cancelled."

How can I change what those two messages say? I think I want to use MsgBox with VBYesNo, but I see any of that on the code the wizard added. How can I change the code so that

1) "You are about to delete 1 records..." to say "You are about to delete one athlete..." and

2) instead of "The DoMenuItem action was cancelled" I want to have "The athlete will not be deleted." to show instead

Any help would be greatly appreciated. Thanks in advance.

-Chris


Here is the default code that the wizard added:

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click

End Sub
 
There is a Delete event for your form.

there you can

a) disable Warnings (docmd.SetWarnings False)

b) set up your Message box to replace the standard warning message with anything that takes your fancy....

c) If you want the option to Cancel the deletion, give your message box a yes/no option. If yes is selected continue the deletion, if no, branch to a line
cancel=True
and print a second messagebox "this athlete has been spared..."
 
Last edited:
Thanks for your help so far. I have the code set up, but what exactly is the "continue with deletion" part of the code look like? Here is what I came up with but I don't know what the delete code looks like:


Private Sub Form_Delete(Cancel As Integer)

DoCmd.SetWarnings (WarningsOff)

MsgBox "Are you sure you want to delete this athlete?", vbYesNo

If vbYes Then
(not sure what goes here)
Else
Cancel = True
End If
End Sub


Or should this go on the button's OnClick event instead?

Also, do I need to do anything with the "Before Delete Confirm" and "After Delete Confirm" events on the form?
 
Your command button generates the delete event by attempting to delete the record. When the delate event happens, you simply intercept the normal caution and replace it with your own.

So the code definitely needs to go in the On Delete event . If the response to the Message box is yes, you do nothing(deletion occurs). If the response is no, you cancel the deletion

DoCmd.SetWarnings False
If MsgBox( "Are you sure you want to delete this athlete?", vbYesNo )=vbNO Then
Cancel = True
MsgBox " This athlete has not been deleted"
Else MsgBox " This athlete has now been deleted"
End If
End Sub
 
One important thing you've all forgot.
You must set the warnings back to true, else this will affect the rest of the database.

DoCmd.SetWarnings False
If MsgBox( "Are you sure you want to delete this athlete?", vbYesNo )=vbNO Then
Cancel = True
MsgBox " This athlete has not been deleted"
Else MsgBox " This athlete has now been deleted"
DoCmd.SetWarnings True
End If
End Sub
 
Code:
DoCmd.SetWarnings False 
If MsgBox( "Are you sure you want to delete this athlete?", vbYesNo ) = vbNO Then 
   Cancel = True 
   MsgBox " This athlete has not been deleted" 
Else 
   MsgBox " This athlete has now been deleted" 
End If 

DoCmd.SetWarnings True

End Sub

Wayne
 
When i run this code, if the checkbox is not ticked it works. Either the Jobcard is complete and it shows the report or it goes to the control. But if you go to the control then tick it, then press yes for complete nothing happens can you help.

If Me.completed.Value = 0 Then


If MsgBox("Is this a Completed Job Card?", vbYesNo) = vbNo Then
DoCmd.GoToControl "completed"

Else
DoCmd.SetWarnings True


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String

stDocName = "jobcardinvoice2"
DoCmd.OpenReport stDocName, acPreview
 

Users who are viewing this thread

Back
Top Bottom