FilterOn MS Access的数据类型不匹配错误

时间:2015-05-31 01:20:34

标签: access-vba ms-access-2010

我完全难过了。这段代码正在运行,目前正在开发一个不同的数据库,但刚刚停止在我正在处理的那个数据库上。我没有理解为什么我在标准中得到数据类型不匹配"当我单步执行代码时,填充的所有数据都是正确的错误。我在这里收到错误:FilterOn = True。我不知道如何调试此代码或如何修复它。

以下是完整的参考代码:

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 个答案:

答案 0 :(得分:1)

错误本身就是标准中的数据类型不匹配

在标准中,您正在检查日期和ID ...日期格式,因为第一次看起来很好,所以最好将'放在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
相关问题