Module to delete record

whoisit

Registered User.
Local time
Today, 02:17
Joined
Oct 27, 2004
Messages
28
I would like to create a module which will run a delete query and when the query is run i would like to show the message "Are you sure you would like to delete this record" and options Yes/No

This module will then be put on a macro so when i click on the button "OK" the module will be run

Any solutions
THANK YOU
 
First thing if you are trying to delete the current record , you add the following code to the onclick event of the button you suggest you want to use without using macros.

Code:
If MsgBox("Are you sure you want to delete this record?",vbYesNo+vbCritical,"Delete this Record!?")= vbYes Then
Docmd.Runcommand acCmdDeleteRecord
End If

Can you clarify if you want to delete the current record or do you want a module where the particular records are deleted by creating a delete query at runtime etc etc?

Or using the following code running a delete query that is already created.

Code:
If MsgBox("Are you sure you want to delete these records?",vbYesNo+vbCritical,"Delete Records!?")= vbYes Then
Docmd.Setwarnings(False)  'Hides Access msgbox's
Docmd.OpenQuery "deletequeryname"   'Runs Delete Query
Docmd.Setwarnings(True)    ' Sets warnings back to true
End If

Andy
 
Last edited:
Thanks a lot spacepro
it was actually the second code i wanted but now that i've seen the first one i may consider it
Now how do i make a macro execute the module
Any solutions please
THANK YOU
 
Personally I don't use macros, because of error handling. To the put the code into a function you can do one or two things.

Create a Module call it say modDeleteRecord.

Then type the following:

Code:
Option Compare Database

Public Function DelRecord()

If MsgBox("Are you sure you want to delete this record?",vbYesNo+vbCritical,"Delete this Record!?")= vbYes Then
Docmd.Runcommand acCmdDeleteRecord
End If

End Function

Then just simply call the function by using :

Code:
Call DelRecord()

You don't need to use macros to trigger the function, just put it on the onclick event of a button or whatever event you want to trigger it.

I would also use my first suggestion, because why would you want to create a delete query when a function within access does it for you.

Good Luck.

Andy
 
Thanks a lot
i was struggling on this bit for some time
THANK YOU
 

Users who are viewing this thread

Back
Top Bottom