confirm upon delete record

fleury

Registered User.
Local time
Today, 07:47
Joined
Jul 2, 2011
Messages
27
hello guys!!!

May i know how to confirm changes before deleting the record in my form??
I have a delete button in the form now.

Thanks very much!!
 
All you need to do is use a message box to prompt the user if they are sure or not. You can either do this on the forms on delete event or under your delete button but either way you'll get the point.

Code:
dim i as integer
 
i = MsgBox("Are you sure you want to delete this record", vbYesNo, "Delete?")
if i = 6 then
     'Delete the record
else
     Cancel = True
end if
 
THanks lots! I try to add tis code to delete onclick event whn i switch to design view. But i notice that i m using macro to make the button function.

So i gotta add in event procedure of onclick event?
But then if i add the code in event procedure, the delete button can't delete any record now.
 
THanks lots! I try to add tis code to delete onclick event whn i switch to design view. But i notice that i m using macro to make the button function.

So i gotta add in event procedure of onclick event?
But then if i add the code in event procedure, the delete button can't delete any record now.

Under the database tools tab you can always convert your macros to visual basic.

Then just add the code you need to show a message box.
 
ok now i add the code under event procedure but the delete button cant function after that.
Is it i need to add the delete macro code back to the visual basic code?
sorry if i make u confused.
 
I try to convert the macro of delete button but there is error occured. Should i add the below code after the code confirm changes?

Private Sub
cmdDelete_Click() rsMyRS.Delete lstRecords.RemoveItem lstRecords.ListIndex End Sub
 
Yes do something like this for your button:

Code:
[COLOR=#0000ff]Private Sub[/COLOR] cmdDelete_Click()
 
dim i as integer, rsMyRS as dao.recordset
set rsMyRS = me.recordsetclone

i = MsgBox("Are you sure you want to delete this record", vbYesNo, "Delete?")
if i = 6 then
     rsMyRS.Delete
     me.lstRecords.RemoveItem
     me.lstRecords.ListIndex
else
     msgbox "The Record was not deleted!", vbokonly
end if
rsMyRS.close
set rsMyRS = Nothing
[COLOR=blue]End Sub[/COLOR]

This is assuming the recordset and the button are all on the same form.
 
I tried with the code u provided but cant. It does not delete record nor show any message box. I also tried with the code below but nothing comes out too.

Code:
Private Sub deleterecord_Click()

 
Dim i As Integer, rsMyRS As dao.Recordset
Set rsMyRS = Me.RecordsetClone

i = MsgBox("Are you sure you want to delete this record", vbYesNo, "Delete?")
If i = 6 Then
     rsMyRS.Delete
     Me.lstRecords.RemoveItem
     Me.lstRecords.ListIndex
Else
     MsgBox "The Record was not deleted!", vbOKOnly
End If
rsMyRS.Close
Set rsMyRS = Nothing

End Sub
 
if you post you db I will take a look at it today as I have a little time. It really sounds like a simple misunderstanding. Let me know.
 
Ok I got it to work but I had to comment out two lines and add me.requery. Worked 100%. Here is the code:

Code:
Private Sub DeleteRecord_Click()
 
Dim i As Integer, rsMyRS As dao.Recordset
Set rsMyRS = Me.RecordsetClone
i = MsgBox("Are you sure you want to delete this record", vbYesNo, "Delete?")
If i = 6 Then
     rsMyRS.Delete
     Me.Requery
     'Me.lstRecords.RemoveItem
     'Me.lstRecords.ListIndex
Else
     MsgBox "The Record was not deleted!", vbOKOnly
End If
rsMyRS.Close
Set rsMyRS = Nothing
End Sub
 
sorry that i have bother you so much thechazm.
I tried insert the latest code and it works on the first record that i wish to delete(for example, record A).
However, if i continue to delete another record(record B), error will occur.
I have attached the picture of the error here to let u understand more.
 

Attachments

  • confirm upon delete error.jpg
    confirm upon delete error.jpg
    89 KB · Views: 396
Ok I'll take a look after I finish a large update that I have to finish.
 

Users who are viewing this thread

Back
Top Bottom