delete

G

Guest

hi
I have a continuous subform set to AllowDeletions = true. I have a delete
button on each record in the subform. On the subform's before delete confirm
event, I have changed the default message and have set up a custom message
instead. In this message I am including the name fields from the record
which will be deleted as additional confirmation for the user. Even though
the correct record is deleted, this confirmation box is showing fields (First
Names and Surname) from the next record in the form! Why is this? And when I
click on the delete button for the very last record in the subform, it says
the names from the previous record in the form in the delete confirmation
message box. Very strange.

Here is the code I'm using for the subform's before delete confirm event:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
' Suppress default Delete Confirm dialog box.
Response = acDataErrContinue
' Display custom dialog box.
If MsgBox("Are you sure you want to remove the driver " & [First Names]
& " " & Surname & " from this vehicle?" & vbNewLine & _
, vbOKCancel) = vbCancel Then
Cancel = True
End If
End Sub

I know that by default when you delete a record, the form shows the next
record in the table or query when the before delete confirmation message box
is displayed (even though the "current" record hasn't been deleted yet.)
Please see the post at

http://www.microsoft.com/office/com...8ada&catlist=&dglist=&ptlist=&exp=&sloc=en-us

(or find this post, "Delete Button Shows Previous Record Before the Current
Record is Deleted" in Access Forms in this forum.)

I imagine this is this something to do with it. Do you know a way around
this? Do I need to put the Application.Echo False into the Before Delete
Confirm code too?

Please help if you can.
TIA
Rich
 
V

Van T. Dinh

I think BeforeDelConfirm Event actually happens AFTER the Record(s) is
deleted from the Form buffer (but the deletion has not been propagated to
the actual Table(s). Hence, the Current Record is the one *after* the
Record which has just been deleted from the buffer.

Check Access VB Help for further info ...

For confirmation Msg, stick the MsgBox in your CommandButton_Click Event and
depending on the Response, proceed or skip the deletion code as required.
 
B

Brendan Reynolds

As Van indicates elsewhere in this thread, you no longer have access (no pun
intended) to the about-to-be-deleted value in the BeforeDelConfirm event
procedure. The last event in which you still have access to this value is
the Delete event procedure. What you could do is use the Delete event
procedure to store the value in a module-level variable, then refer to that
variable in the BeforeDelConfirm event procedure, like so ...

Option Compare Database
Option Explicit

Private mstrValue As String

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)

Response = acDataErrContinue
Cancel = MsgBox("Are you sure you want to delete the record with value
'" _
& mstrValue & "'?", vbYesNo) = vbNo

End Sub

Private Sub Form_Delete(Cancel As Integer)

mstrValue = TestText & vbNullString

End Sub

--
Brendan Reynolds


Rich1234 said:
hi
I have a continuous subform set to AllowDeletions = true. I have a delete
button on each record in the subform. On the subform's before delete
confirm
event, I have changed the default message and have set up a custom message
instead. In this message I am including the name fields from the record
which will be deleted as additional confirmation for the user. Even
though
the correct record is deleted, this confirmation box is showing fields
(First
Names and Surname) from the next record in the form! Why is this? And
when I
click on the delete button for the very last record in the subform, it
says
the names from the previous record in the form in the delete confirmation
message box. Very strange.

Here is the code I'm using for the subform's before delete confirm event:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
' Suppress default Delete Confirm dialog box.
Response = acDataErrContinue
' Display custom dialog box.
If MsgBox("Are you sure you want to remove the driver " & [First Names]
& " " & Surname & " from this vehicle?" & vbNewLine & _
, vbOKCancel) = vbCancel Then
Cancel = True
End If
End Sub

I know that by default when you delete a record, the form shows the next
record in the table or query when the before delete confirmation message
box
is displayed (even though the "current" record hasn't been deleted yet.)
Please see the post at

http://www.microsoft.com/office/com...8ada&catlist=&dglist=&ptlist=&exp=&sloc=en-us

(or find this post, "Delete Button Shows Previous Record Before the
Current
Record is Deleted" in Access Forms in this forum.)

I imagine this is this something to do with it. Do you know a way around
this? Do I need to put the Application.Echo False into the Before Delete
Confirm code too?

Please help if you can.
TIA
Rich
 
G

Guest

Thanks Van

I used the delete button's on click event as you advise. It works!

Van T. Dinh said:
I think BeforeDelConfirm Event actually happens AFTER the Record(s) is
deleted from the Form buffer (but the deletion has not been propagated to
the actual Table(s). Hence, the Current Record is the one *after* the
Record which has just been deleted from the buffer.

Check Access VB Help for further info ...

For confirmation Msg, stick the MsgBox in your CommandButton_Click Event and
depending on the Response, proceed or skip the deletion code as required.

--
HTH
Van T. Dinh
MVP (Access)



Rich1234 said:
hi
I have a continuous subform set to AllowDeletions = true. I have a delete
button on each record in the subform. On the subform's before delete
confirm
event, I have changed the default message and have set up a custom message
instead. In this message I am including the name fields from the record
which will be deleted as additional confirmation for the user. Even
though
the correct record is deleted, this confirmation box is showing fields
(First
Names and Surname) from the next record in the form! Why is this? And
when I
click on the delete button for the very last record in the subform, it
says
the names from the previous record in the form in the delete confirmation
message box. Very strange.

Here is the code I'm using for the subform's before delete confirm event:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
' Suppress default Delete Confirm dialog box.
Response = acDataErrContinue
' Display custom dialog box.
If MsgBox("Are you sure you want to remove the driver " & [First Names]
& " " & Surname & " from this vehicle?" & vbNewLine & _
, vbOKCancel) = vbCancel Then
Cancel = True
End If
End Sub

I know that by default when you delete a record, the form shows the next
record in the table or query when the before delete confirmation message
box
is displayed (even though the "current" record hasn't been deleted yet.)
Please see the post at

http://www.microsoft.com/office/com...8ada&catlist=&dglist=&ptlist=&exp=&sloc=en-us

(or find this post, "Delete Button Shows Previous Record Before the
Current
Record is Deleted" in Access Forms in this forum.)

I imagine this is this something to do with it. Do you know a way around
this? Do I need to put the Application.Echo False into the Before Delete
Confirm code too?

Please help if you can.
TIA
Rich
 

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