2015-04-24 85 views
1

按名稱搜索工作,但是當我試圖還日期進行過濾和它出現這個錯誤:搜索從/名稱,運輸日期

運行時錯誤「3075」:

Syntax error(missing operator) in query expression 'DriverFirst Like'*paul*'TransportDate Like '*4/5/2015*". 

下面你的代碼:

Private Sub Command33_Click() 

    Dim strSQL As String 
    Dim boolBefore As Boolean 

    strSQL = "" 
    boolBefore = False 

    If Len(Me.txtSrch) > 1 Then 
     If (boolBefore) Then 
      strSQL = strSQL & " AND " 
     End If 

     strSQL = strSQL & "DriverFirst Like '*" & Me.txtSrch & "*'" 
    End If 

    If Len(Me.fromDate) > 1 Then 
     If (boolBefore) Then 
      strSQL = strSQL & " AND " 
     End If 

     strSQL = strSQL & "TransportDate Like '*" & Me.fromDate & "*'" 
     boolBefore = True 
    End If 

    Me.Form.Filter = strSQL 
    Me.Form.FilterOn = True 

End Sub 

回答

0

TransportDate就像沒有fromdate

並沒有太大的意義。此外,您必須使用格式正確的字符串表達式作爲日期值,因此:

strSQL = strSQL & " TransportDate = #" & Format(Me!fromDate, "yyyy\/mm\/dd") & "#" 
1

你讓你身在何處之日起串聯星號通配符。我相信Access查詢應該使用散列標記(例如#)來包裝日期和直接比較而不是模式匹配。

strSQL = strSQL & "TransportDate = #" & Me.fromDate & "#" 
+0

再次用黃色標記這個Me.Form.Filter = strSQL –