Delete confirmation Message Box

G

Guest

When I try to delete a record from a form a confirmaiton message box pops up
which asks "are you sure you want ot delete this record" without directly
referencing the record. This is fine. However, at the same itme while the
message box is on the screen the form automatically changes showing the next
record which makes it confusing to some users as to which record is going to
be deleted? How can I prevent Access from switching to the next record until
deletion is confirmd by the user? OR clearly reference the record in the
Message box or both?
 
S

strive4peace

Hi Moe,

are you using a command button to delete? If so, what is the code? If
not, how are your users deleting?

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

Hi Crystal
The answer is yes. Deletion is done by a command button and here is its code
generated by Access:
Private Sub Command49_Click()
On Error GoTo Err_Command49_Click


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

Exit_Command49_Click:
Exit Sub

Err_Command49_Click:
MsgBox Err.Description
Resume Exit_Command49_Click

End Sub
 
M

missinglinq via AccessMonster.com

The problem with using the Command Button Wizard is that you're often stuck
with Access' default behaviour.

Delete your current command button and place a new one on your form.

When the Wizard comes up Click Cancel

Right Click the new button and Click Properties

Click All Tab

Name the button DeleteButton

Click Event Tab

Click to bring up On Click Property

Click on Code Builder

You should be at

Private Sub DeleteButton_Click()
'Place code here
End Sub

Where it says "Place code here" copy and paste this code:

'*********************************************** Code
*************************************************
intResponse = MsgBox("Do you wish to delete this record?", vbYesNo,
"Delete Record")
If intResponse = vbYes Then

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True

Else
Cancel = True

End If
'******************************************* End Code
*************************************************

Now when you click on the Delete Button, a messagebox will pop up asking the
user if they really want to delete the record. The record in question will
still be visible until a choice is made.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
M

missinglinq via AccessMonster.com

Love this forum but hate the formatting! Be sure when copying the code not to
copy the

'*********************************************** Code
*************************************************

and the

'******************************************* End Code
*************************************************

part or Access will throw an error code. Just copy the part in between!
 
G

Guest

thank you for your help. I did as you said then it gave me an error on
intResponse and Cancel (where it says Cancel= True) as "variable not
defined". I added "Dim intResponse As String" but do not know how to declare
Cancel.
Moe
 
G

Guest

After my last post I deleted the line "cancel=True" and it is working fine.
Hope it is not going to cause any problem later
Moe
 
M

missinglinq via AccessMonster.com

I'm sorry, Moe! The code I gave you was originally used in a different event,
not a click event. Cancel can only be used in certain subs> You should be
just fine!
 

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