2017-08-30 59 views
0

已經運行一個程序數週,現在進入groomer時間到數據庫。從來沒有遇到過問題。隨機Bug開始出現

昨天第一次進入工作正常,沒問題。 第二次輸入時發生錯誤。

昨天沒有時間看它,所以只是手動輸入所有的時間。

今天同樣的事情。第一次進入,完美運作,沒有問題。 第二次輸入,會引發錯誤。

的代碼將停止在這條線:

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 

在一個爲什麼突然發生這種全部損失以及爲什麼它是隨機的

任何建議,將不勝感激。

回答

1

您需要格式化您的日期表達式:

strCriteria = "([PetID] = '" & pid & "') And ([ApptDate] = #" & Format(aptdate, "yyyy\/mm\/dd") & "#)" 

如果PID是數字,而不是文本:

strCriteria = "([PetID] = " & pid & ") And ([ApptDate] = #" & Format(aptdate, "yyyy\/mm\/dd") & "#)" 
+0

978項後面是時候開始發生,格式化 ' 「&PID&」' 以「&pid&」似乎修復它,到目前爲止大聲笑 –