Use Switch in query criteria based on combo box

TimTDP

Registered User.
Local time
Today, 22:50
Joined
Oct 24, 2008
Messages
213
On I form I have a combo box called cboMobileStatus.
Its row source type is "Value List"
The row source is: 1;" All";2;"Has";3;"None"

I have a query based on table "tblCustomerContacts" and I want to limit the records returned based on the value of the combo box.
So if the user selects:
* All (1) I want all records returned.
* Has (2) I only want records that have a mobile number returned
* None (3) I only want records that do not have a mobile number returned

The field mobile is text (to keep the leading 0)
I thought of using the Switch function in the criteria of the query for field Mobile like this:
Code:
Switch([Forms]![frmPrintCustomer]![cboMobileStatus]=1,([tblCustomerContacts].[Mobile]) Like "*",[Forms]![frmPrintCustomer]![cboMobileStatus]=2,([tblCustomerContacts].[Mobile]) Is Not Null,[Forms]![frmPrintCustomer]![cboMobileStatus]=3,([tblCustomerContacts].[Mobile]) Is Null)
but the query does not like it!

Am I on the right track, and if so, how should I modify the code?
If not, how should I be doing this?

Manny thanks
 
You might consider changing the record source and add WHERE clauses for the 2 cases of Has and None to return just those records.

All: SELECT * FROM tblCustomerContacts;
None: SELECT * FROM tblCustomerContacts WHERE tblCustomerContacts.Mobile IS NULL;
Has: SELECT * FROM tblCustomerContacts WHERE tblCustomerContacts.Mobile IS NOT NULL;
 

Users who are viewing this thread

Back
Top Bottom