Toli
Toli

Reputation: 109

How to avoid alert "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"

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.

Upvotes: 1

Views: 1798

Answers (1)

Andre
Andre

Reputation: 27634

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

Upvotes: 1

Related Questions