Warning supression isnt working :(

spacemunkee

New member
Local time
Today, 10:46
Joined
Mar 5, 2007
Messages
6
Private Sub Command40_Click()
On Error GoTo Err_Command40_Click

DoCmd.SetWarnings False 'Turn Warnings Off
DoCmd.RunCommand acCmdSaveRecord
DoCmd.SetWarnings True 'Turn Warnings On
Exit_Command40_Click:
Exit Sub

Err_Command40_Click:
MsgBox Err.Description
Resume Exit_Command40_Click

End Sub

In essence its just a save record button which has a macro attached to it to run on mouse down. This macro runs a query to update a table which then updates the form upon saving. The warning messages to say it is deleting the old table and updating with new values keeps popping up even though im using the above code. Any idea on how to supress these warning dialogues when i click save?
 
Two things:

1) You won't get a warning when you go to save a record
2) The warnings are occurring when you run the macro. The code you attached would work if it ran the macro in between the two SetWarnings lines.

You could turn the warnings off and on within the macro itself; turning them off before any queries are run, then on again once they're finished.

Regards,
Pete
 
As a side note, make sure you add the Set Warnings True also in the Error Handler (wherever you use it) otherwise you may end up without warnings at all if it errors out and doesn't get to the code to turn them on again
Private Sub Command40_Click()
Code:
On Error GoTo Err_Command40_Click

    DoCmd.SetWarnings False 'Turn Warnings Off
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.SetWarnings True 'Turn Warnings On
Exit_Command40_Click:
    Exit Sub

Err_Command40_Click:
   [B] DoCmd.SetWarnings True [/B]
    MsgBox Err.Description
    Resume Exit_Command40_Click
    
End Sub
 
As a side note, make sure you add the Set Warnings True also in the Error Handler (wherever you use it) otherwise you may end up without warnings at all if it errors out and doesn't get to the code to turn them on again
Private Sub Command40_Click()
Code:
On Error GoTo Err_Command40_Click
 
    DoCmd.SetWarnings False 'Turn Warnings Off
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.SetWarnings True 'Turn Warnings On
Exit_Command40_Click:
    Exit Sub
 
Err_Command40_Click:
   [B]DoCmd.SetWarnings True [/B]
    MsgBox Err.Description
    Resume Exit_Command40_Click
 
End Sub

How would one turn warning back on if it did error out and there was no error handler for it?
 
How would one turn warning back on if it did error out and there was no error handler for it?

Go to your IMMEDIATE WINDOW in the VBA window and type in

DoCmd.SetWarnings True

and then hit enter.

That will reset them. Then make sure to add error handling as I said.
 
Go to your IMMEDIATE WINDOW in the VBA window and type in

DoCmd.SetWarnings True

and then hit enter.

That will reset them. Then make sure to add error handling as I said.

This is why some programmers use a exit sub section in their code

EXIT_SUB:
DoCmd.Setwarnings True
Wrap up all other stuff you touched
Exit Sub

ERR_HANDLER:
Show Error
Trap Error
Etc
GoTo EXIT_SUB:

It has its advantages in this type of scenario
 

Users who are viewing this thread

Back
Top Bottom