多场填充要求

时间:2013-12-11 16:20:27

标签: access-vba

strFilter导致以下内容,但不会传递给Me.Filter,任何想法为什么?
strFilter =“'20410'或'A20000'或'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

End Sub

1 个答案:

答案 0 :(得分: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