Delete Button shows previous record before current record is delet

G

Guest

hi
I have a form and a delete command button to delete the record from the
form. The problem is that after the delete button is pressed, before the
access confirm delete message appears, the form displays the next record in
the table before the record in question is deleted! So from the user's point
of view, the record they had selected for deleting is no longer displayed
when they are being asked to confirm deletion. If the user selects cancel to
the delete confirmation message, the form reverts to showing the (correct)
record that the user originally selected for deletion.

What is causing this? And what is the solution?
TIA
Rich
 
R

Rick B

There is no "solution", this is the correct reflex. It is basically saying,
OK, here is what the database will look like if you continue. Is this what
you want? Are you sure?"
 
G

Guest

It happens because the record is cut and can be pasted back if you decide not
to delete. To get round it, put the statement

Application.Echo False

before the delete code and then put this statement after the delete code. If
you have used the code that is generated by the delete button wizard then
also put the statement below as the first line in your error trap code.

Application.Echo True
 
G

Guest

Thanks for your posts guys.
Where do I find the "delete code?" I have tried using VBA (by putting an
event procedure in the OnDelete event and including Application.Echo False)
but it caused Access to crash. My database has crashed several times
recently and may be corrupt (I will deal with this shortly) so putting this
issue aside, how should I go about finding and changing the "delete code"?

you said I should put Application.Echo True in the error trap code of the
delete button. Is this found in the onclick property of the button at the
bottom of the code where it says

Err_Remove_Vehicle_From_Database_Click:
MsgBox Err.Description
Resume Exit_Remove_Vehicle_From_Database_Click

Is this the right place to put this? Please help! This is all new to me
Thank you
 
G

Guest

Your delete button should have event procedure against its On Click property.
Can you post this code and we can check and advise ?
 
G

Guest

Here is the onclick event procedure for Delete Button:

Private Sub Remove_Vehicle_From_Database_Click()
On Error GoTo Err_Remove_Vehicle_From_Database_Click

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

Dim bAllow As Boolean
bAllow = Not Me.AllowEdits
Me.AllowEdits = bAllow
Me.AllowAdditions = bAllow
Me.AllowDeletions = bAllow
Me.ComLokVehRec.Caption = IIf(bAllow, "&Lock", "Un&Lock")
Me.Label132.Visible = IIf(bAllow, "False", "True")
Me.Label135.Visible = IIf(bAllow, "True", "false")
Me.Box123.BorderColor = IIf(bAllow, "255", "16711680")
Me.Box133.Visible = IIf(bAllow, "False", "True")
Me.Box134.Visible = IIf(bAllow, "True", "False")
Me.Remove_Vehicle_From_Database.Visible = IIf(bAllow, "True", "False")
Me.Combo112.Locked = False

Exit_Remove_Vehicle_From_Database_Click:
Exit Sub

Err_Remove_Vehicle_From_Database_Click:
MsgBox Err.Description
Resume Exit_Remove_Vehicle_From_Database_Click

End Sub

I tried putting
Application.Echo False before the first line of the following two lines and
after the second
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

(Is this right?) I also put Application.Echo True at where I think the
error trap is, as shown on my last post.
When I tried deleting on the form, the previous record wasn't displayed but
Access then locked up and I had to restart Access. I'm having lots of
crashes... but, putting that to one side for now, should the procedure work
as described above? Am I doing it right?
 
G

Guest

Add my 3 Application.Echo lines as below

Rich1234 said:
Here is the onclick event procedure for Delete Button:

Private Sub Remove_Vehicle_From_Database_Click()
On Error GoTo Err_Remove_Vehicle_From_Database_Click
Application.Echo False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Application.Echo True
 
G

Guest

Thanks Dennis. It works.
I did try this before but Access kept crashing. I have just turned off
Update Auto Name Correct which has fixed this problem, and many others!

Many thanks for sage advice
Rich
 
G

Guest

Hi Dennis

I have used your technique in a continuous subform which works beautifully
(record about to be deleted is still showing when delete confirm message is
displayed.)
I have just customised the delete confirm message and have included fields
(First Names and Surname) from the record about to be deleted for further
confirmation for the user. But the names from the next record in the table
appear in the message (even though the correct record is then actually
deleted.) And if I select the last driver in the form for deletion, the
message uses the names from the previous record.

Is this a problem which can be overcome by the Application.Echo statement,
presumably somewhere in the Before Delete Confirm event? Here is the code
I'm using in the Before Delete 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?" , vbOKCancel) = vbCancel Then
Cancel = True
End If
End Sub

If you're able to help and share your expertise, I'd be immensely grateful.

Thanks
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