现在已经运行了几个星期的程序,它将groomer时间输入数据库。从未遇到任何问题。
昨天,第一次进入工作正常,没有问题。 第二次输入错误。
昨天没有时间查看它,所以只是手动输入。
今天,同样的事情。第一次进入,工作完美,没有问题。 第二次输入,抛出错误。
代码在此行停止:
If DCount("[PetID]", "[TimeLog]", strCriteria) > 0 Then
使用运行时3464,标准表达式中的数据类型不匹配
该部分的整个代码:
'Set variables for error checking duplicates
Dim pid As Integer
Dim aptdate As Date
pid = CmbPetName.Column(2)
'MsgBox (pid)
aptdate = txtAptDate.Value
'MsgBox (aptdate)
Dim strCriteria As String
'Set Criteria for DCount()
strCriteria = "([PetID] = '" & pid & "') And ([ApptDate] = #" & aptdate & "#)"
'MsgBox (strCriteria)
'Error checking for duplicates
If DCount("[PetID]", "[TimeLog]", strCriteria) > 0 Then
MsgBox ("Record Already Exists")
Exit Sub
End If
完全失去了为什么突然发生这种情况,以及为什么它是随机的
对此的任何建议将不胜感激。
答案 0 :(得分:1)
您需要格式化日期表达式:
strCriteria = "([PetID] = '" & pid & "') And ([ApptDate] = #" & Format(aptdate, "yyyy\/mm\/dd") & "#)"
如果pid是数字,而不是文字:
strCriteria = "([PetID] = " & pid & ") And ([ApptDate] = #" & Format(aptdate, "yyyy\/mm\/dd") & "#)"