所以我有一个 ms access 2010 db,它通过 odbc 连接具有链接表。
我有一个完成交易的宏(库存申请)。当多用户使用宏时,宏会重叠并产生错误。
我把宏变成了一个公共函数,这有助于但没有消除问题。
我试图让它使用事务方法,如果不是全部完成,它可以回滚。
我认为我非常接近,但我在运行查询时遇到问题,并且担心这是因为表通过 odbc 连接链接到 sql。我在下面发布代码。如果有人有任何想法,将不胜感激。
选项比较数据库
'------------------------------------------------------------
' CompleteTransactionsMOD
'
'------------------------------------------------------------
Public Function CompleteTransactionsMOD()
Dim bSuccess As Boolean
Dim iCounter As Integer
Do While bSuccess = False And iCounter < 3
Debug.Print "Loop " & iCounter
bSuccess = CompleteTransactionsMOD_Loop()
iCounter = iCounter + 1
Loop
If bSuccess Then
MsgBox "Transactions completed successfully"
Else
MsgBox "Transactions failed to complete after repeated attempts"
End If
End Function
Public Function CompleteTransactionsMOD_Loop() As Boolean
DBEngine.BeginTrans
On Error GoTo CompleteTransactionsMOD_Loop_Err
With CurrentDb
.Execute "UpdateInOutTrantblQRY", dbFailOnError
.Execute "UpdateTranTypeQRY", dbFailOnError
.Execute "PullToShipTransHandlingQRY", dbFailOnError
.Execute "TransreadyInDupLocQRY", dbFailOnError
.Execute "TransreadyOutDupLocQRY", dbFailOnError
.Execute "AppendNewLocToInvInQry", dbFailOnError
.Execute "UpdateNewLocToInvNegQRY", dbFailOnError
.Execute "TrancomplastQRY", dbFailOnError
.Execute "InvLocFindNegQRY", dbFailOnError
.Execute "DelZeroQInvLocQRY", dbFailOnError
End With
DBEngine.CommitTrans
CompleteTransactionsMOD_Loop = True
CompleteTransactionsMOD_Loop_Exit:
Exit Function
CompleteTransactionsMOD_Loop_Err:
DBEngine.Rollback
Debug.Print Err.Description
CompleteTransactionsMOD_Loop = False
Resume CompleteTransactionsMOD_Loop_Exit
End Function