1

我想禁用 Access 中的默认 msgbox。这是我的代码,

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,我想将其更改为我自己的消息框。

4

2 回答 2

2

您可以使用 Form_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

其他错误可能是:

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
于 2013-02-19T13:31:55.163 回答
0

尝试这个:

DoCmd.SetWarnings false
Application.DisplayAlerts = false
于 2013-02-19T12:51:41.703 回答