2013-12-11 67 views
0

strFilter的結果如下,但不會貫徹到Me.Filter中,爲什麼?
strFilter的= 「 '20410' OR 'A20000' OR 'A20400'」多場過濾要求

Private Sub Image_OffsetFilterButton_Click() 
Dim strFilter As String 
strFilter = "'A20410'" 
    '/ see if there is data in Field Box Text907, if so add it to the filter 
    If Me!Text907 & vbNullStr <> vbNullStr Then 
    strFilter = strFilter & " OR " & "'" & "A20000" & "'" 
End If 
    If Me!Text910 & vbNullStr <> vbNullStr Then 
    ' If FieldB is of Text type, use the ' delimiter 
    strFilter = strFilter & " OR " & "'" & "A20024" & "'" 
End If 
    If Me!Text911 & vbNullStr <> vbNullStr Then 
' If FieldB is of Text type, use the ' delimiter 
    strFilter = strFilter & " OR " & "'" & "A20400" & "'" 
End If 
'/<etc> 


If strFilter <> "" Then 
' trim off leading "OR" 
    Me.Filter = "[Account] = strFilter AND [BU] = 'B50931'" 
    Me.FilterOn = True 
Else 
    Me.Filter = "" 
    Me.FilterOn = False 
End If 

結束子

回答

1
Private Sub Image_OffsetFilterButton_Click() 
Dim strFilter As String 
strFilter = "" 
'/ see if there is data in Field Box Text907, if so add it to the filter 
If Me!Text907 & vbNullStr <> vbNullStr Then 
    strFilter = strFilter & " OR [ACCOUNT] = '" & Me.Text907 & "'" 
    End If 
If Me!Text910 & vbNullStr <> vbNullStr Then 
    '/ If FieldB is of Text type, use the ' delimiter 
    strFilter = strFilter & " OR [ACCOUNT] = '" & Me.Text910 & "'" 
    End If 
If Me!Text911 & vbNullStr <> vbNullStr Then 
    '/ If FieldB is of Text type, use the ' delimiter 
    strFilter = strFilter & " OR [ACCOUNT] = '" & Me.Text911 & "'" 
End If 
'/<etc> 

    If strFilter <> "" Then 
    '\ trim off leading "OR" 
    Me.Filter = Mid(strFilter, 4) 
    Me.FilterOn = True 
Else 
    Me.Filter = "[BU] = [Forms]![Frm_Main]! [Frm_Main_TextBox_Display_BU_Number_HIDDEN].Value" 
    Me.FilterOn = False 
End If 
End Sub