我想从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,我想将其更改为我自己的消息框。
答案 0 :(得分: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
答案 1 :(得分:0)
试试这个:
DoCmd.SetWarnings false
Application.DisplayAlerts = false