I have a summary report by BatchId and it is filtering fine. The detail
report that does not have BatchId in the output is giving me an error -
"Enter Parameter Value tblBatchPickList.BatchID"
(tblBatchPickList.BatchID
is the field I am trying to filter on.) I am assuming it is asking
because
it can not find that field.
The report's data is based on a embedded query that has tblBatchPickList
in
the table list, but not in the output of the query.
:
Just because the value doesn't appear on the report doesn't mean you
can't
use the field to filter what rows are in the RecordSource for the report.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
New spin on the old question...
I have a report that works off this same text box. The report uses
these
batch ids to LIMIT the records but it does not USE the batch id field
in
the
output so I can't filter by that field, right? The report takes these
multiple batch ids and cross references them to a materials list and
then
groups and subtotals by the raw material item (not the batch id). What
do
I
do now? How do I use multiple strings in a combo box to limit records
in
a
report but not output that field in the report itself?
:
Perfect!!! I knew I must have been missing something with the [Notes]
reference. Thank you all!
:
You must have the name of the field against which you're comparing:
that's
what Allen meant by [Notes] in his original example. Replace [Notes]
with
the appropriate field name.
The string you use as a filter must repeat the name of the field for
each
comparison. That means you need something like:
Me.Filter = "([Notes] Like '*0506*') OR ([Notes] Like '*0517*') OR
([Notes]
Like '*0515*') OR ([Notes] Like '*0516*')"
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
message
I can not use the multi-select list box - there are just too many
user
defined possibilities (although I printed the article for a
different
project
- thanks.)
I tried the code you provided for multiple keywords and I had two
issues
1) the code... strWhere = strWhere & "([Notes] Like ""*" &
strWord &
"*"") OR " ...what does the [Notes] mean? For it to work I had
to
revise
the code to be... strWhere = strWhere & "Like ""*" & strWord &
"*""
OR "
(Per the Locals window this is working fine)
2) When I try to run the code and get to the line "Me.Filter =
Left(strWhere, lngLen)" I get a run time error "run-time error
'2448': You
can't assign a value to this object." I can not figure out what
is
wrong...the Left function give the correct sting (I tested that
separately)
PS I made sure the form is set to allow filters, just in case that
was the
problem.
:
The query will not be able to interpret multiple criteria like
that, so
you
will need to generate the filter string in code.
For individual values (not wildcards), you could use an unbound
multi-select
list box on your form, and build the string as shown in this
article:
Use a multi-select list box to filter a report
at:
http://allenbrowne.com/ser-50.html
The article explains how to build the WhereCondition for a
report,
but
building the Filter for a form is identical.
Another option would be just to type all the values into a text
box
separated by spaces, and use code like this to build the filter
string:
Private Sub txtKeywords_AfterUpdate()
Dim strWhere As String
Dim strWord As String
Dim varKeywords As Variant 'Array of keywords.
Dim i As Integer
Dim lngLen As Long
If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
If IsNull(Me.txtKeywords) Then 'Show all if blank.
If Me.FilterOn Then
Me.FilterOn = False
End If
Else
varKeywords = Split(Me.txtKeywords, " ")
If UBound(varKeywords) >= 99 Then '99 words max.
MsgBox "Too many words."
Else
'Build up the Where string from the array.
For i = LBound(varKeywords) To UBound(varKeywords)
strWord = Trim$(varKeywords(i))
If strWord <> vbNullString Then
strWhere = strWhere & "([Notes] Like ""*" &
strWord
&
"*"") OR "
End If
Next
lngLen = Len(strWhere) - 4 'Without trailing " OR
".
If lngLen > 0 Then
Me.Filter = Left(strWhere, lngLen)
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End If
End If
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
message
I have a form with a combo box (BatchID) that when changed will
populate
the
detail in the form. I want to be able to use multiple
wildcard
strings to
search the database for the detail. For example, I want to
enter
*0506* or *0515* or *0516*
and get all records where there is a 0506, 0515 OR 0516 in the
BatchId
field. This works fine in the query directly, but when I put
the
text
in
the
combo box, it will not bring back the data.
I have tried
[Forms]![frmBatch Pick List]![BatchID]
Like "*"&[Forms]![frmBatch Pick List]![BatchID]&"*"
Like [Forms]![frmBatch Pick List]![BatchID]
but they do not work if I add multiple wildcard requests to
the
BatchID
combo box.