modify warning message

W

Wendy

Hi, How can I intercept and modify the "You are about to
delete 1 record(s)" popup message to read "you are about
to delete record number ### , patient_name " ?

Thanks!
 
D

Douglas J. Steele

I don't believe you can change the message. It's an all-or-nothing
proposition: you either see the message, or you don't.

You can turn it off using SetWarnings, and then manually display your own
personal message though.
 
A

Allen Browne

That would involve an interplay of events.

In a datasheet, for example, you can select several records, and then press
delete to delete several at once. The Delete event occurs for each record
being deleted, and the record number is available at that time. Then the
BeforeDelConfirm event occurs once for all the records being deleted. This
is where the message pops up. You can easily replace the message with your
own in this event, but the details of the records are not available at this
time.

So, to achieve what you want, you would need to:
1. Declare a string variable in the General Declarations section (top) of
the form's module.

2. Concatenate the record numbers into the string in the Delete event.

3. Use that string to display the message in the BeforeDelConfirm event, and
clear the string.
 
6

'69 Camaro

Hi, Wendy.

You can't really "intercept" this error message, but you can turn it off and
use your own message in your VBA procedure to warn the user. You can either
turn off the warnings in code, or you can turn off the warnings by using the
database options. However, if you do this using the database options, then
if the user opens the table and deletes records, no message will warn the
user.

To turn off the warning in code, use syntax such as the following:

MsgBox "You are about to delete record #" & RecID & ", " & Patient_Name
& "!"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True ' Turn warnings back on for subsequent code.

Make sure that the error handler for this procedure sets the warnings back
on, just in case something goes wrong. Otherwise, no further system
warnings will be displayed for the user during the current session.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
W

Wendy

Thank You Doug
-----Original Message-----
I don't believe you can change the message. It's an all- or-nothing
proposition: you either see the message, or you don't.

You can turn it off using SetWarnings, and then manually display your own
personal message though.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)





.
 
W

Wendy

Thanks Gunny.
-----Original Message-----
Hi, Wendy.

You can't really "intercept" this error message, but you can turn it off and
use your own message in your VBA procedure to warn the user. You can either
turn off the warnings in code, or you can turn off the warnings by using the
database options. However, if you do this using the database options, then
if the user opens the table and deletes records, no message will warn the
user.

To turn off the warning in code, use syntax such as the following:

MsgBox "You are about to delete record #" & RecID & ", " & Patient_Name
& "!"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True ' Turn warnings back on for subsequent code.

Make sure that the error handler for this procedure sets the warnings back
on, just in case something goes wrong. Otherwise, no further system
warnings will be displayed for the user during the current session.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)





.
 
W

Wendy

Thanks for the reply. But I guess I also need to know how
or where to access the Delete and BeforeDelConfirm events
in my code. I'm using a control button to initiate the
delete record event. Please excuse my ignorance.

Thanks again,
Wendy
 
A

Allen Browne

1. Open your form in design view.
2. Open the Properties box (View menu).
3. Making sure the title of the properties box says "Form" (so you are
looking at the properites of the form, not those of a text box), you will
find the On Delete and BeforeDelConfirm on the Events tab of the properties
box.

4. At the top of the form's module, add:
Dim strKeyList As String

5. Set up the Delete event procedure so it looks like this (replacing
PatientID with the name of your key field:
Private Sub Form_Delete(Cancel As Integer)
strKeyList = strKeyList & Me.[PatientID] & ", "
End Sub

6. Set up the BeforeDelConfirm event procedure so it looks like this:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim strMsg As String

strMsg = "Delete Key #" & vbCrLf & Left(strKeyList, Len(strKeyList) - 2)
strKeyList = ""
If MsgBox(strMsg, vbOKCancel, "Confirm Deletion") <> vbOK Then
Cancel = True
End If
Response = acDataErrContinue
End Sub
 
W

Wendy

Thanks for the very explicit instructions. It Works!
One funny thing though, If I am at record #5 of 10
records, and I repeatedly press the "Delete Records" menu
button, records 5 through 9 are deleted without a warning
message. At record 10 I get the message: "Delete Key #
5,6,7,8,9,10 <OK> <Cancel>" at which point pressing OK
deletes record 10, or pressing "Cancel" leaves record 10
but 5-9 is still gone. what's happening?

Thanks for your persistence
Wendy
-----Original Message-----
1. Open your form in design view.
2. Open the Properties box (View menu).
3. Making sure the title of the properties box says "Form" (so you are
looking at the properites of the form, not those of a text box), you will
find the On Delete and BeforeDelConfirm on the Events tab of the properties
box.

4. At the top of the form's module, add:
Dim strKeyList As String

5. Set up the Delete event procedure so it looks like this (replacing
PatientID with the name of your key field:
Private Sub Form_Delete(Cancel As Integer)
strKeyList = strKeyList & Me.[PatientID] & ", "
End Sub

6. Set up the BeforeDelConfirm event procedure so it looks like this:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim strMsg As String

strMsg = "Delete Key #" & vbCrLf & Left(strKeyList, Len(strKeyList) - 2)
strKeyList = ""
If MsgBox(strMsg, vbOKCancel, "Confirm Deletion") <> vbOK Then
Cancel = True
End If
Response = acDataErrContinue
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Thanks for the reply. But I guess I also need to know how
or where to access the Delete and BeforeDelConfirm events
in my code. I'm using a control button to initiate the
delete record event. Please excuse my ignorance.

Thanks again,
Wendy
occurs
for each record that
time. Then the not
available at this


.
 
G

George Nicholson

Wendy:

Be sure to read the help file entry on the BeforeDelConfirm event. It will
fire ONLY if the user has the Tools>Options>Edit/Find>Confirm: Record
Changes box checked. You'll need to decide how much you want to rely on
this.

--
George Nicholson

Remove 'Junk' from return address.


Allen Browne said:
1. Open your form in design view.
2. Open the Properties box (View menu).
3. Making sure the title of the properties box says "Form" (so you are
looking at the properites of the form, not those of a text box), you will
find the On Delete and BeforeDelConfirm on the Events tab of the properties
box.

4. At the top of the form's module, add:
Dim strKeyList As String

5. Set up the Delete event procedure so it looks like this (replacing
PatientID with the name of your key field:
Private Sub Form_Delete(Cancel As Integer)
strKeyList = strKeyList & Me.[PatientID] & ", "
End Sub

6. Set up the BeforeDelConfirm event procedure so it looks like this:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim strMsg As String

strMsg = "Delete Key #" & vbCrLf & Left(strKeyList, Len(strKeyList) - 2)
strKeyList = ""
If MsgBox(strMsg, vbOKCancel, "Confirm Deletion") <> vbOK Then
Cancel = True
End If
Response = acDataErrContinue
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Wendy said:
Thanks for the reply. But I guess I also need to know how
or where to access the Delete and BeforeDelConfirm events
in my code. I'm using a control button to initiate the
delete record event. Please excuse my ignorance.

Thanks again,
Wendy
 
A

Allen Browne

Yes, that's interesting behavior, isn't it. It appears that if you hit the
delete key repeatedly and fairly quickly, Access treats them as one multiple
deletion and fires the BeforeDelConfirm event once for them all, just as if
you had made a multiple selection and deleted them as one operation.

If that is not the behavior you want, you could just use the Delete event.
That would definately fire once per record, even if you did select multiple
records to delete at once.

George Nicholson's reply is important too. If you are using AfterDelConfirm,
then you might want to ensure that confirmations are turned on in your
initialization code when the database starts (e.g. in the Open event
procedure of your startup form). The code would be:
If Not Application.GetOption("Confirm Record Changes") Then
Application.SetOption ("Confirm Record Changes"), True
End If

If the application is ever upsized, the order of events is different also:
http://support.microsoft.com/?id=234866

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Wendy said:
Thanks for the very explicit instructions. It Works!
One funny thing though, If I am at record #5 of 10
records, and I repeatedly press the "Delete Records" menu
button, records 5 through 9 are deleted without a warning
message. At record 10 I get the message: "Delete Key #
5,6,7,8,9,10 <OK> <Cancel>" at which point pressing OK
deletes record 10, or pressing "Cancel" leaves record 10
but 5-9 is still gone. what's happening?

Thanks for your persistence
Wendy
-----Original Message-----
1. Open your form in design view.
2. Open the Properties box (View menu).
3. Making sure the title of the properties box says "Form" (so you are
looking at the properites of the form, not those of a text box), you will
find the On Delete and BeforeDelConfirm on the Events tab of the properties
box.

4. At the top of the form's module, add:
Dim strKeyList As String

5. Set up the Delete event procedure so it looks like this (replacing
PatientID with the name of your key field:
Private Sub Form_Delete(Cancel As Integer)
strKeyList = strKeyList & Me.[PatientID] & ", "
End Sub

6. Set up the BeforeDelConfirm event procedure so it looks like this:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim strMsg As String

strMsg = "Delete Key #" & vbCrLf & Left(strKeyList, Len(strKeyList) - 2)
strKeyList = ""
If MsgBox(strMsg, vbOKCancel, "Confirm Deletion") <> vbOK Then
Cancel = True
End If
Response = acDataErrContinue
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Thanks for the reply. But I guess I also need to know how
or where to access the Delete and BeforeDelConfirm events
in my code. I'm using a control button to initiate the
delete record event. Please excuse my ignorance.

Thanks again,
Wendy

-----Original Message-----
That would involve an interplay of events.

In a datasheet, for example, you can select several
records, and then press
delete to delete several at once. The Delete event occurs
for each record
being deleted, and the record number is available at that
time. Then the
BeforeDelConfirm event occurs once for all the records
being deleted. This
is where the message pops up. You can easily replace the
message with your
own in this event, but the details of the records are not
available at this
time.

So, to achieve what you want, you would need to:
1. Declare a string variable in the General Declarations
section (top) of
the form's module.

2. Concatenate the record numbers into the string in the
Delete event.

3. Use that string to display the message in the
BeforeDelConfirm event, and
clear the string.


message
Hi, How can I intercept and modify the "You are about to
delete 1 record(s)" popup message to read "you are about
to delete record number ### , patient_name " ?

Thanks!
 
Top