Running Code based on User's Response to delete macro

timothyd

Registered User.
Local time
Today, 05:25
Joined
Feb 9, 2010
Messages
41
Hello,

I am using the standard delete macro that the access button creator has. I added a line to the macro that runs a vba code segment, but I only want this to run if the user presses yes to deleting the record. Is there a condition that I can write that will allow me to determine if the user pressed yes or no and run the code accordingly? Thanks.
 
Hello,

I am using the standard delete macro that the access button creator has. I added a line to the macro that runs a vba code segment, but I only want this to run if the user presses yes to deleting the record. Is there a condition that I can write that will allow me to determine if the user pressed yes or no and run the code accordingly? Thanks.

You would have to use an if statement with a vb command something like this

Dim LResponse As Integer
LResponse = MsgBox("Do you wish to continue?", vbYesNo, "Continue")
If LResponse = vbYes Then
{...statements...}
Else
{... statements...}
End If
 
I would do that naturally, but I'm not doing the delete in the vba code but rather using the default record delete that Access gives you in the macro builder. I could switch everything to the vba code if someone could help me by getting all same code from the macro builder the the vba script. Otherwise, I'm looking for a way to get the user's response from the msgbox that pops up for them if they really want to delete or not. Thanks for the help though.
 
I would do that naturally, but I'm not doing the delete in the vba code but rather using the default record delete that Access gives you in the macro builder. I could switch everything to the vba code if someone could help me by getting all same code from the macro builder the the vba script. Otherwise, I'm looking for a way to get the user's response from the msgbox that pops up for them if they really want to delete or not. Thanks for the help though.


If you are using the MACRO side of Access then you can convert the macro into script, follow these steps:

Create a new form in design view, then show the database window, look for your MACRo and drag it onto the form, this will generate a button, tehn if using Access 2003 go to the Tools menu and MACRO and convert the form macro to VBA, if using 2007 use the Database Tools Tab and on the left Convert the MACRO to VBA, you then have the VBA script behind the button which you can edit or add to as necessary.
 
Ok thanks, I converted the code into vba. Now, to delete the record, I call this method

DoCmd.RunCommand acCmdDeleteRecord

is there a way to get a return value from that, or will I have to create my own message box and then run this code based on the users response? The following return values have not worked:

returnValue = DoCmd.RunCommand (acCmdDeleteRecord)
returnValue = DoCmd.RunCommand acCmdDeleteRecord
if DoCmd.RunCommand (acCmdDeleteRecord) = 0 then
 
In your MACRO before converting it to the code you could add an extra action to add a message box and then when you convert the macro it will give ou the code. Otherwise you just add your own based on the if statement

IF me.Text.Value = "" Then
msgbox"Please Enter a value"
Else
Exit Sub
End if

The above is only an example
 

Users who are viewing this thread

Back
Top Bottom