Msgbox styles

goodhead

Registered User.
Local time
Today, 02:24
Joined
Feb 18, 2013
Messages
37
I have a del query that I want to run from a button.

When clicked I want a msgbox asking "are you sure you want to delete?"
then have yes and no options.

if yes is pressed it run my query. if no it closes form.

I know I need to mess with styles but cant get them to work.

I'm sing access 2010.


help please.

Dan
 
Perhaps the following code in the On Click event of the button:
Code:
    If MsgBox("Are you want to run the DELETE query", vbYesNo + vbCritical + vbDefaultButton2, "Confirmation Required") = vbYes Then
        'Run your query
    Else
        DoCmd.Close acForm, Me.Name
    End If
 
Thanks, i'll try. I'm not a coder so what do I put in code to link to query?
You put run your query.


Perhaps the following code in the On Click event of the button:
Code:
    If MsgBox("Are you want to run the DELETE query", vbYesNo + vbCritical + vbDefaultButton2, "Confirmation Required") = vbYes Then
        'Run your query
    Else
        DoCmd.Close acForm, Me.Name
    End If
 
Wow, its working.
I'm so pleased.

One just small thing i'm sure you'll know.

As its a del query it sais about deleting x number of rows etc.

Can I turn those warnings off? I just want the yes/no box.

in macro builder its called setwarnings. I guess this needs to be in the code. If you know, can you add into what you posted already so I know where its placed.

Thanks


Something like:
DoCmd.OpenQuery "YourQueryName"
 
Hi , sorted last thing. Added DoCmd.SetWarnings False to the beginning before the if statement.

Thanks
 
Be sure to turn them back on.

Dale
 
That will work, BUT, you MUST use
DoCmd.SetWarnings True
after the query has been run.
This is VERY IMPORTANT.
 
Sorry if I being stupid.

But why? I hate access unfriendly messages.

Or is there another reason why you both saying I should do this.


That will work, BUT, you MUST use
DoCmd.SetWarnings True
after the query has been run.
This is VERY IMPORTANT.
 
So you will now if something unfriendly hits the fan.

That is what error handling in code is for.
Dale
 

Users who are viewing this thread

Back
Top Bottom