Query criteria for combo filter

Danick

Registered User.
Local time
Today, 01:50
Joined
Sep 23, 2008
Messages
375
I’m having difficulty with the results from a query that that is run from a combo box. This maybe very basic, but just can’t figure it out.
There is a form with a few combos with drops downs for customers, contacts, etc... The bound column is 1 which is the ID of the customer, contact, etc.
The query I use to transfer to an excel spreadsheet has this in the criteria for the customer and contact

Code:
Like "*" & [Forms]![frmSummary].[Form]![cboCustomer] & "*"
Like "*" & [Forms]![frmSummary].[Form]![cboContact] & "*"

If I fill both combos, the query works fine. But if I leave the contact combo blank and run the query, I get everything with the customer IDs that have that ID in it. For example, if I pick a company like ABC Company that has a company ID of “1”, then I also get all the other companies with the number 1 in the Company ID.
How can I make this so that it only returns the records with the company id that is in the drop down.
Thanks
 
First, we know nothing of your database. Your code references Customers and Contacts, your explanation starts off that way, but then you introduce the term 'Companies' which seems unrelated to your code.

Now, since you are searching on an actual ID field, it seems to me there's no reason to LIKE that field. Do a simple = comparison and return the specific ID that matches. I would actually say that for anything you are using a combo box to search. there's no reason to do a LIKE from a drop down. If however, you had an input box and users typed in characters themselves, then the LIKE would be appropriate, but a combo box ensures an exact match will be made.
 
How can I make this so that it only returns the records with the company id that is in the drop down.
depends on the context - ID is a number, but like is used for text and * are wildchars

change to

= [Forms]![frmSummary].[Form]![cboCustomer]

If I fill both combos, the query works fine. But if I leave the contact combo blank and run the query,
you haven't provided enough information to provide an answer other than you need to cater for where one of the combos is null. Provide the full sql of the criteria if you require further help
 
depends on the context - ID is a number, but like is used for text and * are wildchars

change to

= [Forms]![frmSummary].[Form]![cboCustomer]

Thanks CJ. This got me part of the way.
Just had to change both queries to

Code:
[Forms]![frmSummary].[Form]![cboCustomer] or [Forms]![frmSummary].[Form]![cboCustomer] Is Null

[Forms]![frmSummary].[Form]![cboContact] or [Forms]![frmSummary].[Form]![cboContact] Is Null


Then when I saved it, the query actually added 4 more lines to account for the other search parameters.

Seems to be working now.
Thanks for your help...
 

Users who are viewing this thread

Back
Top Bottom