creating FORM delete button coding

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

Guest

hi, ive 'created' a delete record button in a form as i know absolutely no
VB, but i also want it to run a macro Msgbox, (that ive created) which
displays a warning msgbox before anything deletes. However, when the delete
buttons are created via the wizard it obviously creates an event procedure in
vb. Im assuming i would have to use a VB function that calls the macro to be
run before deletion, but i dont know any vb coding.

Any help will be appreciated

Thanks in advance
Connie :)
 
Put the following code in the Click event of your Delete button:
Dim MsgStr As String
Dim TitleStr As String
MsgStr = "Are You Sure You Want To Delete This Record?"
TitleStr = "Confirm Delete Record"
If MsgBox(MsgStr,vbYesNo,TitleStr) = vbNo Then
Exit Sub
End If
DoCmd.SetWarnings False
DoCmd.RunCommand acDeleteRecord
DoCmd.SetWarnings True
 
The message shows up when i press delete, but its not deleting now.
error message 'Run time error 2501. the Run command action was cancelled'
and it points to: DoCmd.RunCommand acDeleteRecord
 
Sorry, my mistake!

Change DoCmd.RunCommand acDeleteRecord
To
DoCmd.RunCommand acCmdDeleteRecord

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com
 
Thanks. it works now

PC Datasheet said:
Sorry, my mistake!

Change DoCmd.RunCommand acDeleteRecord
To
DoCmd.RunCommand acCmdDeleteRecord

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com
 
When I use this code in Access 2002, it does delete the current record, but
generates Error #3709: "The search key was not found in any record", and the
debugger points to the line: Change DoCmd.RunCommand acCmdDelete Record.
Where should I look for the problem? Thanks!
 
Back
Top