2015-05-31 74 views
1

我完全難住了。此代碼正在工作,目前正在處理不同的數據庫,但只停留在我正在處理的那個數據庫上。當我通過代碼填充填充的所有數據是正確的時,爲什麼我得到「標準中的數據類型不匹配」錯誤沒有任何意義。我在這裏得到錯誤:FilterOn = True。我不知道如何調試此代碼或如何解決它。FilterOn MS Access數據類型不匹配錯誤

下面是引用的完整代碼:

Me.searchlat = TempVars("user").Value 
Dim strWhere As String 
Dim lngLen As Long 

Const conJetDate = "\#mm\/dd\/yyyy\#" 

If Not IsNull(Me.searchlat) Then 
strWhere = strWhere & "([workerid] = " & Me.searchlat & ") AND " 
    End If 

If Not IsNull(Me.txtStartDate) Then 
strWhere = strWhere & "([Dateassigned] >= " & Format(Me.txtStartDate, conJetDate) & ") AND " 
    End If 

If Not IsNull(Me.txtEndDate) Then 
strWhere = strWhere & "([Dateassigned]< " & Format(Me.txtEndDate + 1, conJetDate) & ") AND " 
    End If 

lngLen = Len(strWhere) - 5 
If lngLen <= 0 Then 
MsgBox "No criteria", vbInformation, "Nothing to do." 
Else 
strWhere = Left$(strWhere, lngLen) 

Me.Filter = strWhere 
Me.FilterOn = True 

回答

1

本身是說數據類型不匹配的標準誤差

在您檢查日期和ID..Date格式標準是罰款,每首先看起來更好,把'的ID和檢查如下..

Me.searchlat = TempVars("user").Value 
Dim strWhere As String 
Dim lngLen As Long 

Const conJetDate = "\#mm\/dd\/yyyy\#" 

If Not IsNull(Me.searchlat) Then 
strWhere = " ([workerid] = '" & Me.searchlat & "') " 
    End If 

If Not IsNull(Me.txtStartDate) Then 
strWhere = strWhere & " AND ([Dateassigned] >= " & Format(Me.txtStartDate, conJetDate) & ") " 
    End If 

If Not IsNull(Me.txtEndDate) Then 
strWhere = strWhere & " AND ([Dateassigned]< " & Format(Me.txtEndDate + 1, conJetDate) & ") " 
    End If 

lngLen = Len(strWhere) - 5 
If lngLen <= 0 Then 
MsgBox "No criteria", vbInformation, "Nothing to do." 
END IF 

Me.Filter = strWhere 
Me.FilterOn = True 
+0

經過13小時的重寫此代碼,你是一個生命的救星! – Lilly

相關問題