Ron:
How you get it to do what's required depends on the combo box's BoundColumn
property. This determines what the value of the control is when you make a
selection. The default is 1 so the value would be the first column,
CustomerID If it is 1, or anything apart from 2 for that matter, you'd
examine the value of the property for Null. Often the control's AfterUpdate
event procedure is used so that the relevant action is undertaken once an
item is selected. I assume in your case you want to restrict the records
returned on the basis of the selection, but return all records if <ALL> is
selected, so you might do something like this:
If IsNull(Me.YourComboBox) Then
' show all the records
Else
' show a restricted set of records
End If
Just what code you'd use to show all or a restricted set of records depends
on how you are showing the records. If you are filtering the current form
for instance then you'd set its Filter property; if you are opening another
form or a report then you'd use the WhereCondition argument of the OpenForm
or OpenReport method.
Alternatively if you are using a reference to the combo box as a parameter
in a query to restrict the rows returned then you'd extend the criterion in
the query with a Boolean OR operation so it tests for the control being Null,
e.g.
WHERE (CustomerID = Forms!YourForm!YourComboBox OR
Forms!YourForm!YourComboBox IS NULL)
If the combo box's BoundColumn property is 2 the its value would be <ALL>
if you select that item so in that case instead of testing for it being Null
you'd test for:
YourComboBox = "<ALL>".
Ken Sheridan
Stafford, England
Ron Weaver said:
Hi Ken
Thanks for the reply.
I used Doug's code and now have the <ALL> in the combo.
Now all I have to do is figure out how to get it to function.
Thanks again!
Ron
Ken Sheridan said:
Ron:
You don't say which column is the combo box's BoundColumn, but it looks like
it might be the StartDate column, so on that basis:
SELECT [Customer Query].CustomerID, [Customer Query].Expr1, [Customer
Query].StartDate, [Customer Query].Phone, Orders.OrderID, 1 AS SortColumn
FROM [Customer Query] INNER JOIN Orders ON [Customer Query].OrderID =
Orders.OrderID
WHERE ((([Customer Query].StartDate) Between
[Forms]![frmSearchCustomerOrders]![txtStartDate] And
[Forms]![frmSearchCustomerOrders]![txtEndDate]))
UNION
SELECT NULL, NULL, "<ALL>", NULL, NULL, 0
FROM [Customer Query]
ORDER BY SortColumn, [Customer Query].StartDate;
The SortColumn column contains the constants 0 and 1 in each half of the
UNION operation; this causes the second half to sort first. The second half
of the UNION operation would actually return as many identical rows as are
returned by the [Customer Query] but as a UNION operation suppresses
duplicate rows only one is returned in the result set. You can in fact use
anything in the FROM clause of the second half of the UNION operation as it
only returns constants and Nulls, so any table could be used there rather
than the [Customer Query].
Ken Sheridan
Stafford, England
:
I have a combo box used to view specific customer records. I would like to
add <ALL> to my Search By Date combo box as the default value. Below is my
current SQL:
SELECT [Customer Query].CustomerID, [Customer Query].Expr1, [Customer
Query].StartDate, [Customer Query].Phone, Orders.OrderID
FROM [Customer Query] INNER JOIN Orders ON [Customer Query].OrderID =
Orders.OrderID
WHERE ((([Customer Query].StartDate) Between
[Forms]![frmSearchCustomerOrders]![txtStartDate] And
[Forms]![frmSearchCustomerOrders]![txtEndDate]))
ORDER BY [Customer Query].StartDate;
Would someone please show me how to do this?
Thanks
Ron