1

I wrote a code to call a module on the button click in Access form and when I click on d button, i recieve d following alerts:

"You won't be able to undo the changes this action query is about to make to the data in a linked table or tables"

and

"You are about to update X row(s)".

The code behind the button is:

Private Sub UpdateRS_Click()
    Call UpdateModul.Update
End Sub

And module is:

Public Function Update()
DoCmd.RunSQL "Update tbl03 INNER JOIN tblMaster " & _
 "ON tbl03.KW = tblOnd_RS.KW " & _
 "SET tbl03.CAp = [tblMaster].[CAp] "
End Function

How to avoid these alert messages? I appreciate any help.

Erik A
  • 31,639
  • 12
  • 42
  • 67
Toli
  • 109
  • 1
  • 4
  • 13

1 Answers1

1

See http://www.fmsinc.com/microsoftaccess/query/action-queries/SuppressWarningMessages.htm and http://www.utteraccess.com/wiki/index.php/RunSQL_vs_Execute .

You could use

DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE ..."
DoCmd.SetWarnings True

but this has multiple problems, e.g. an error could prevent DoCmd.SetWarnings True from running, which then could lead to disaster.

Much better is:

Dim db As DAO.Database
Set db = CurrentDb  
db.Execute "UPDATE ...", dbFailOnError
Andre
  • 26,751
  • 7
  • 36
  • 80
  • Hi Andre, I used your first code, it is working, thank you very much. So far, I am satisfied with it, and I didn't understand the second code, but doesn't matter. – Toli Sep 16 '16 at 07:43