禁用默认消息框
Posted
技术标签:
【中文标题】禁用默认消息框【英文标题】:Disable default msgbox 【发布时间】:2013-02-19 12:46:45 【问题描述】:我想禁用 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,我想将其更改为我自己的消息框。
【问题讨论】:
关闭警告通常不是一个好主意,您认为这些 msgbox 与什么有关? 在什么情况下会出现这种情况? 我想禁用 msgbox 的访问权限并使用我自己的 msgbox。我有上面写的代码 Good :) 从不使用 DoCmd.SetWarnings False 并且违反了该规则,请确保重新打开警告。它不会像您认为的那样做,它是系统范围的,它会给您带来无穷无尽的问题。 现在重新切换警告!见***.com/questions/14957869/… @Remou He he ^_^,将我们链接回这个问题,不过你已经提供了关于 Andrey 答案的正确链接。 【参考方案1】:您可以使用 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
【讨论】:
【参考方案2】:试试这个:
DoCmd.SetWarnings false
Application.DisplayAlerts = false
【讨论】:
我已经厌倦了这个,仍然无法工作。我是否需要说明用户是否在“所需日期”中输入字母才能输入日期?? 绝不将警告设置为假! ***.com/questions/11213892/…Application.DisplayAlerts
在 Access 中不起作用,只能在 Excel 中使用以上是关于禁用默认消息框的主要内容,如果未能解决你的问题,请参考以下文章