473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Query to search for all records based on combo box

Hi,

I have a table containing analyst information, and each analyst has a
unique ID (30 analysts, analyst IDs are 1,2,3,...29,30).

I am creating a search form which feeds an underlying query with the
search parameters, and returns the results in a subform. I have used
a SELECT query to populate the "ComboAnalyst" combo box, and have
added a UNION query to add an "All" option to the list:

SELECT Analysts.Analyst_ID, Analysts.LastName FROM Analysts WHERE
(((Analysts.Role)="AN"))
ORDER BY Analysts.LastName
UNION SELECT "*" ,"(All)" FROM Analysts;

The problem arises when I try to search for records for all analysts.
The initial SQL statement contained the following to find records:

....
WHERE ... AND ((Analysts.Analyst_ID) Like "*" &
[Forms]![frmQueryRatings]![ComboAnalyst] & "*"))
....

This works fine to select records for all analysts, and also works
fine for analysts who have a larger number Analyst_ID. However, on
choosing the analyst with Analyst_ID = 1, records for analysts with
Analyst_ID = 1, 10, 11, 12 etc are returned.

By removing the wildcards completely from the SQL conditions:

....
WHERE ... AND ((Analysts.Analyst_ID) =
[Forms]![frmQueryRatings]![ComboAnalyst]))
....

individual analyst records can easily be found, but the "All" option
no longer returns any records.

I have been racking my brains over this for a long time, and seem to
be getting nowhere - if anyone can help it would be greatly
appreciated.

Thanks

Dom Boyce
Nov 12 '05 #1
2 6230
Hi Dom

The simple way of doing this is to put an IIf statement into your SQL that
takes out the wildcard if a *specific* analyst has been selected.

Something along the lines of:

WHERE ... AND
(IIf([Forms]![frmQueryRatings]![ComboAnalyst]="*","*",Analysts.Analyst_ID) =
IIf([Forms]![frmQueryRatings]![ComboAnalyst]="*","*",[Forms]![frmQueryRating
s]![ComboAnalyst])

hth

~Ben
Nov 12 '05 #2
Dom
Thanks a lot for that, Ben - it worked a treat!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Daniel Tan | last post by:
Are there anyway to copy rows of records from one query to another query and then hide the records in source query ? Pls advise. Thanks. Regards, Daniel
4
by: Robert | last post by:
Greetings I am assisting a developer with an Access application performance problem and an ODBC timeout. In a nutshell they have a combo box with a drop down that queries a lookup table on a SQL...
2
by: RBohannon | last post by:
I have a report with most fields populated by a query. However, some of the fields are variable in such a way that their values cannot be queried from a table. At present the values for these...
0
by: Jason | last post by:
I have a primary form which is used to enter/edit data in a table named Test_Results. On this primary form there is a subform which displays site addresses. This subform is linked to the primary...
1
by: Sue | last post by:
I have a main form based on a member list, so that I can add details. I also have a query which takes its parameters from a textbox on the form to search for a surname so that I can delete the...
5
by: Rated R1 | last post by:
I wrote this before in the NGs, so I am going to paste the responses that I got and see if someone can please help me. Email me and we can set something up as Id even be willing to pay for your...
6
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
2
by: Zeljko | last post by:
I'm creating Address book. Header of the main form (frmAddress) contains combo box (cboFilter) to filter records by Occupation on main Form(Ocupation1). That's working. Combo box also have "Show...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.