使用ODBC链接的sql表进行MS访问的事务方法

时间:2012-05-12 23:01:51

标签: sql odbc

所以我有一个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

0 个答案:

没有答案