我正试图强制用户以“ 18/7/2019”格式输入日期。如果用户以非此格式输入日期,我希望错误消息显示“格式错误”。我该怎么办?
On Error GoTo Update_Exit:
Dim db As DAO.Database
Dim qdf As QueryDef
Dim sql As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("SearchEffectiveDate")
sqlString = "SELECT KissFlowtbl.* FROM KissFlowtbl WHERE Effective_Date Like '*" & Me.txtEffectiveDate & "*' "
qdf.sql = sqlString
If Nz(Me.txtEffectiveDate, "") = "" Then
MsgBox "Please enter Effective Date"
Resume Exit_Update
Else
MsgBox "Wrong Format"
Resume Exit_Update
End If
DoCmd.OpenQuery "SearchEffectiveDate"
qdf.Close
CurrentDb.Close
Exit_Update:
Exit Sub
Update_Exit:
If Err.Number = 2501 Then
Resume Exit_Update
Else
MsgBox Err.Description
Resume Exit_Update
End If
End Sub
答案 0 :(得分:0)
这并不容易,实际上不是这种格式的。您可以查看使用ISO格式时的管理方式:
Entering ISO formatted date with input mask and full validation in Microsoft Access
如果您没有帐户,请浏览链接:阅读全文。
代码也在 GitHub 上:VBA.DateEntry