ACC: Update or Delete Query Fails Without Generating Error (117163)
The information in this article applies to:
- Microsoft Access 1.0
- Microsoft Access 1.1
- Microsoft Access 2.0
This article was previously published under Q117163
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you run an update or delete query in code using the Execute
method, some records are not modified or deleted, and no error message is
generated.
CAUSE
Those records that were not modified or deleted were locked when the action
query was run. A record is locked whenever it is being edited, whether that
editing is done through the user interface, from code, or by an action
query.
RESOLUTION
In Microsoft Access version 2.0, use the DB_FAILONERROR argument when you
use the Execute method to run an action query from code. This switch issues
a rollback and generates an error when locking conflicts occur, resulting
in the cancellation of all updates. The following is a code example showing
the use of the DB_FAILONERROR argument and error trapping:
Option Explicit
Function RunUDQuery ()
Dim db As Database, qdef As QueryDef
Set db = CurrentDB()
Set qdef = db.QueryDefs("UDQuery")
On Error GoTo Errorhandler
qdef.Execute DB_FAILONERROR
Exit Function
Errorhandler:
MsgBox "Update Failed " & Err & " " & Error
Exit Function
End Function
In Microsoft Access version 1.x, create a dynaset in Access Basic code that
includes all the records that should be modified. Within transactions
(BeginTrans and CommitTrans), modify each record in the dynaset until all
the records are updated. This technique will generate an error that you can
trap if a locking conflict occurs. You can then issue a rollback on the
transaction and try to update the record again until the update succeeds.
STATUS
This behavior no longer occurs in Microsoft Access version 7.0.
Modification Type: | Major | Last Reviewed: | 5/6/2003 |
---|
Keywords: | kbbug kbusage KB117163 |
---|
|