You could do it in the same way with:
Like Forms!YourForm!YourComboBox & "*"
Note that the asterisk wildcard character need to be in quotes. However,
this requires the user to know that they have to leave the combo box Null to
return all rows, so is not very intuitive. A better approach would be to
include something like 'All' in the list. You can do this with a value list
as the combo box's RowSource if the values are fixed:
All;Open;Closed
or you can use an SQL statement which will list 'All' plus whatever values
are in the column in the table, so this is better if the value list is not a
list of fixed predetermined values, e.g. if the list were one of customers or
cities:
SELECT "All" AS Status, 0 AS OrderColumn
FROM YourTable
UNION
SELECT Status, 1
FROM YourTable
ORDER BY OrderColumn, Status;
As a UNION operation suppresses duplicates you'll get only one instance of
each value. The OrderColumn with the constants 0 or 1 as its values ensures
that the 'All' row comes first in the list whatever the other values are.
Whichever way you do it the criteria for the Status column in query design
view should be:
Forms!YourForm!YourComboBox Or Forms!YourForm!YourComboBox = "All"
If the user selects Open or Closed then the first part of this Boolean OR
operation will evaluate to TRUE for those rows containing the selected value,
so only those rows would be returned. If the user selects 'All' then the
second part of the OR operation will evaluate to TRUE for every row, so all
rows would be returned. If you save the query and then open it again in
design view you'll fund that Access has moved things around a bit, but it
will still work the same.
The DefaultValue property of the combo box should be set to 'All' so this
appears in the control when the form opens. The following code should be out
in the combo box's AfterUpdate event procedure so that, if a user sets the
value to Null by deleting the selected value it will automatically be set
back to 'All'
If IsNull(YourComboBox) Then
YourComboBox = "All"
End If
Ken Sheridan
Stafford, England
Ben Watts said:
I want to use a form, so they have a drop down list. How would I link it
back to the query and also be able to choose both Open and Closed at the same
time?
Maurice said:
In your query you could set the parameter in your criteria field:
like [choose status] & *
This way when the user chooses Open he will only see the status open, when
he chooses closed the will only see closed. When he chooses nothing he'll see
all.
If you want to implement this in a form where the user first has to choose
from the form you could implement a unbound control which you can refer to in
your query.
hth
--
Maurice Ausum
:
Ok, I am a newby here. I have a report called MDB Data that is ran from a
query called MDB Data Query. What I want to happen is when the report is
clicked, I want it to prompt for a status parameter that gives the option of
Open or Closed. The field related to this is called Problem Status. Also,
is there a way to choose both Open and Closed at the same time instead of one
at a time?
The look of the parameter, I assume, can be created in a Form?