2014-10-21 64 views

回答

1

你可以把錯誤在表單級別處理,像這樣:

Private Sub Form_Error(DataErr As Integer, Response As Integer) 
    Const conDuplicateKey = 3146 
    Dim strErrMsg As String 

    Select Case DataErr 
     Case conDuplicateKey: 
      strErrMsg = "Record already exists in the database!" 
     ' TODO: add other error codes 
     Case Else 
      Response = acDataErrDisplay 
    End Select 

    If strErrMsg <> vbNullString Then 
     MsgBox strErrMsg, vbCritical, Me.Caption 
     ActiveControl.Undo 
     Response = acDataErrContinue 
    End If 
End Sub 
相關問題