我有一个名为“Test_Daily”的表。实际上我想停止/阻止在其“Today_Date”字段中输入相同的日期。下面是我的代码,适用于其他字段,但是当我在日期/时间字段上尝试它时,给我一个“数据类型未命中匹配”的错误。以下是我的代码,任何人都可以帮忙。
代码:
Private Sub btnTempCheckDup_Click()
Dim Vr_newDate As String
Dim VR_linkCriteria As String
Vr_newDate = Me.txtTempSave.Value
VR_linkCriteria = "[Today_Date] = " & "'" & Vr_newDate & "'"
If Me.txtTempSave = DLookup("[Today_Date]", "Test_Table", VR_linkCriteria) Then
MsgBox "This Date " & Vr_newDate & " Has Already Entered into the Database"
End If
End Sub
答案 0 :(得分:0)
为日期使用格式正确的字符串表达式:
Vr_newDate = Format(Me.txtTempSave.Value, "yyyy\/mm\/dd")
VR_linkCriteria = "[Today_Date] = #" & Vr_newDate & "#"