禁用默认MSGBOXMSGBOX

2023-09-08 11:22:48 作者:独言

我想禁用从Access默认MSGBOX。这是我的code,

I want to disable the default msgbox from Access. This is my code,

Private Sub textRequiredDate_AfterUpdate()

DoCmd.SetWarnings False

If Not IsDate(textRequiredDate.Value) Then
MsgBox "Please enter a date"

Else

End If

If textRequiredDate.Value < textOrderDate.Value Then
MsgBox "Required date must be after Order Date"
textOrderDate.SetFocus
textRequiredDate.SetFocus
textRequiredDate.Value = ""

Else

End If

End Sub

当我写我的要求,我得到了默认的MS接入MSGBOX日期的信,我想将其更改为自己的消息框。

When I write letters on my date required I get the default MS access msgbox, I want to change it to my own message box.

推荐答案

您可以用Form_Error事件创建自定义的错误,例如这是一个有效性规则的错误:

You can create a custom error with the Form_Error event, for example this is for a Validation Rule error:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
      If DataErr = 2107 Then
         MsgBox "There was an error."
         Response = acDataErrContinue
      End If
End Sub

其他错误可能是:

Other errors might be:

Private Sub Form_Error (DataErr As Integer, Response As Integer)
  Const REQUIREDFIELD_VIOLATION = 3314
  Const INPUTMASK_VIOLATION = 2279
  Const DUPLICATEKEY_VIOLATION = 3022
  If DataErr = DUPLICATEKEY_VIOLATION Then
     MsgBox "There was a key violation!"
     Response = acDataErrContinue
  End If
End Sub
 
精彩推荐
图片推荐