command button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello
is there any way to put some kind of confirmation into a delete command
button in a form ? something like a question that ask you if you are realy
want to delete this record....
thanks
 
vassilis said:
hello
is there any way to put some kind of confirmation into a delete command
button in a form ? something like a question that ask you if you are realy
want to delete this record....
thanks

If MsgBox("Are you sure", vbYesNo, "Confirm Delete") = vbYes Then...
(your delete code)
End If
 
One way of doing this

Msg = "You are about to delete the record," & Chr(13) & "Do You want to
Continue to do this?" & Chr(13) & "Yes, Delete, No skip this function?"

Style = vbYesNo + vbExclamation + vbDefaultButton1
Title = "Confirm Delete Record"
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then
Exit Sub
End If
Your code to delete the current record here

End sub

If you use the button wizard for record operation, Delete record, the code
for that asks you to confirm delete anyway.
 
Thanks All for your replays but i dont understand where im gonna write this
code :)
can u advice me pls ?
 
thanks Rick for your replay but as i told to Mike too I dont know where to
write this code ....
thanks
 
vassilis said:
thanks Rick for your replay but as i told to Mike too I dont know where to
write this code ....
thanks

I was assuming you already had a button that deleted the record. Is that the
case? If so, then you modify the existing code that is there.

If you do not have a button yet then all you really need to do is add a new
command button with the control wizard turned on. One of the wizard options for
a new button is to delete the current record and by default you will already get
a confirmation prompt for that.
 
This is code that appears in a button raised for deleting the current record
using the wizard.

Private Sub Command14_Click()
On Error GoTo Err_Command14_Click


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





Exit_Command14_Click:
Exit Sub

Err_Command14_Click:
MsgBox Err.Description
Resume Exit_Command14_Click

End Sub

The Do.Cmd lines are there to provide you with a question which confirms
deletion. Select yes deletes the current record, selecting no exits without
deleting.

If you have problems using the wizard, post back here

Hope this helps
 
Im sorry Mike but i have no idea about coding...
i made the button using the wizard and there is that code :

Private Sub button_Click()
On Error GoTo Err_button_Click


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

Exit_button_Click:
Exit Sub

Err_button_Click:
MsgBox Err.Description
Resume Exit_button_Click

End Sub


do i have to add your code ?

Msg = "You are about to delete the record," & Chr(13) & "Do You want to
 
Hi Vassills,

Now that you have made the button using the wizard, what happens when you
press the button?

Please make sure you have backed up you database before any mods tho?

Pressing the button should ask you to confirm if you wish to delete prior to
any deletions. If you press yes, the current record will be deleted, if you
press no, the button returns you to your form without any deletion. You do
not need to add any code in this case.

The code I provided was in case you had formed the button without the
wizard. In which case, the code would be placed in the on click event of the
button. (With the form in design mode, right click the button and select
properties and select the on click event)

I Really hope this helps you? Please let me know.

Kindest regards

Mike
 
I tried these:
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
But it simply deletes my record. It does not ask me to confirm my deletion.
Does the DoCmd operate differently in different versions of MS Access? I am using 2000.


EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
Take a look at your database options. You might have turned off the
warnings. Click on Tools>Options>Edit/Find tab. You will see a box of
confirmations. Make sure all are checked.

A good way to insure that the warnings are on at the time of the action is
to put this line before the DoCmd that deletes:
DoCmd.SetWarnings True
 
I am also trying to provide functionality to a delete button. I set it up
using the command button wizard and the code created is the same as given in
the previous thread. But when I go to use the Delete Button, the only thing
that happens is that an anonymous toolbar type area on the left hand of my
form changes to black. It does not delete the record, nor does it give the
'do you really wanta delete' message. All the confirm options are set to
display in the tools menu. What else may be needed?
 
What version of Access are you using?????

Mike B
--
An Engineers Prayer:
At the very end of the day,
when all else fails,
you have tried all,
you have shouted at and blamed the innocent,
and asked everyone you know,

READ THE INSTRUCTION MANUAL.
 
Sorry for the delay in replying. Access 2003.

MikeJohnB said:
What version of Access are you using?????

Mike B
--
An Engineers Prayer:
At the very end of the day,
when all else fails,
you have tried all,
you have shouted at and blamed the innocent,
and asked everyone you know,

READ THE INSTRUCTION MANUAL.
 
Hi, now its my turn to apologise for the delay, cannot answer during the day.

Take a look at you form, in design view, select form properties and set
allow deletions to yes.

I think you will now find that the delete button works, if not check also
that the form is open in edit mode.

hth Mike B

--
An Engineers Prayer:
At the very end of the day,
when all else fails,
you have tried all,
you have shouted at and blamed the innocent,
and asked everyone you know,

READ THE INSTRUCTION MANUAL.
 
Thanks for responding when you can. I did check the AllowDeletes and
AllowEdits properties and both say yes. Yet I get the same response. One
other clue is that the undo button on the standard toolbar is disabled when I
open the form. Yet I can do adds and changes. Confusing. Other ideas?

Bev
 
What is Data Entry set to? I have simulated it with Data Entry Yes, Changing
to No allows deletions but I will have to read up on the propert control?

hth

Mike B

--
An Engineers Prayer:
At the very end of the day,
when all else fails,
you have tried all,
you have shouted at and blamed the innocent,
and asked everyone you know,

READ THE INSTRUCTION MANUAL.
 
Ok, what is the Data Entry property set to?

If you don't want the form to display existing records, set the DataEntry
property to Yes. (This setting wont allow your to delete and the undo button
is grey)

If you want the form to open with all records showing, set the DataEntry
property to No. (This setting allows deletions and the undo button is blue)

At the end of the day, it has to be one of the property settings that is
preventing deletion. Give the above a try and let me know????

hth Mike B

--
An Engineers Prayer:
At the very end of the day,
when all else fails,
you have tried all,
you have shouted at and blamed the innocent,
and asked everyone you know,

READ THE INSTRUCTION MANUAL.
 
That 'clunk' you just heard was me hitting my forehead when I realize what is
causing this. I added some code to the 'On Current' event to control changes.
I disable both the AllowEdits and the AllowDeletions but enable edits for the
Change command button I added. I failed to do the same thing for the Delete
button.

I am new at adding code so did not even think to check this. Your statement
that it had to be a property setting prompted me to compare the settings for
a form with the issue and one without and I then remembered the code.

All that said ... I have not tried it yet but will shortly. I'll let you
know what happens.

Bev
 

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

Back
Top