473,399 Members | 3,919 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,399 software developers and data experts.

How do I combine three columns into one drop box in order to perform a search?

I have a db with a table that has many columns of info for various entities. In this table, there are three columns called, entity name, second entity name and third entity name. I need to combine all three columns into one drop box so a search can be done. Once the correct entity name is found, I need to be able to select it and bring up a form with all the data for that entity. For example, say there is an entity that has a name change so the new name becomes the entity name and the old name is the second entity name. If I search by the old name, I want to be able to select it and have all of that data come up in the form including the current entity name. I know this is probably very confusing so please help and let me know if I can clarify anything.
Aug 7 '09 #1
36 3789
ChipR
1,287 Expert 1GB
What kind of search are you trying to do with a combo box? Would the user visually search through the data? This seems like something that could be done via DLookup, but more details are required.
Aug 7 '09 #2
The search is just a form with one drop box that would only have all the entity names in it whether it be the first, second or third entity name. Once the user finds the name they are looking for, I could either have a button and do an OnClick command or just do an AfterUpdate command. After either command, another form would open with the rest of the data for that entity. Does this help?
Aug 7 '09 #3
ChipR
1,287 Expert 1GB
Did you try the combo box wizard and add your key field and the 3 name fields? The key field would be the bound column of the combo box and that would be the value that you use to filter the other form.
I think that AfterUpdate is good with a subform or other controls on the same form, but a button is preferable if you are going to pop up another form.
Aug 7 '09 #4
I tried the combo box wizard, but it lays it out as a drop box with three separate columns. I want all the columns combined into one column.
Aug 7 '09 #5
ChipR
1,287 Expert 1GB
Perhaps you can use a UNION to get them all together.
Expand|Select|Wrap|Line Numbers
  1. SELECT id, name1 FROM myTable
  2.  UNION 
  3. SELECT id, name2 FROM myTable
  4.  UNION 
  5. SELECT id, name3 FROM myTable
Aug 7 '09 #6
Sorry, forgot to mention that. I did a union and that got all the entities into one column, but then I ran into another issue. When I would click on any entity name that was in the second or third entity name column of the table, the subform that was opened would not populate with any data. If I would click on an entity that was in the first entity name column, it would populate the subform with all the data.
Aug 7 '09 #7
ChipR
1,287 Expert 1GB
There must be an issue with the key field then. Did you try keeping the key column visible in the combo box for testing or msgbox the filter value before opening the other form? The problem could be in the underlying query SQL, the combo box setup, or the code to show the record. If you have switched to a subform, are you setting the source or using Master/Child link fields?
Aug 7 '09 #8
I think the union query that I have will work, but I can't figure out how to get an id field in there. There is an id field in the table that the entity names are coming from, but how do I combine that to the entity name in the union query?
Aug 7 '09 #9
ChipR
1,287 Expert 1GB
What's your SQL for the Union, in comparison to mine in Post #6?
Aug 7 '09 #10
That does work. I hadn't looked at it closely enough, but now the problem is that there won't necessarily be something populated in every field, so there are a lot of blanks in the drop list. Also, how do I hide that ID field now?
Aug 7 '09 #11
ChipR
1,287 Expert 1GB
To hide the first column, change the Column Widths property of the combo box to
0";X"
The X being the width of the second column.

I think you can eliminate the Nulls just by changing the query to

SELECT id, Name1 FROM myTable WHERE Name1 <> NULL
UNION
etc.
Aug 7 '09 #12
You are wonderful!!!! It is working perfectly now. Thank you so much for your much needed help!!!!
Aug 7 '09 #13
ChipR
1,287 Expert 1GB
You're very welcome.
Aug 7 '09 #14
Okay, one more question with the same db. I have another column that I need to do the same thing with. It is a modification number column. There are four that I combined into one. There are duplicates in the columns though, so I just need the specific mod number listed once no matter which column it comes from in the table. I still need to have the id number in order to populate my table correctly. Any suggestions?
Aug 7 '09 #15
ChipR
1,287 Expert 1GB
If all duplicates have the same ID, then you can add the key word DISTINCT to the select query on your union. If not then...have to think about that.
Aug 10 '09 #16
No, all the duplicates have different ids. I just have to make it complicated. :)
Aug 10 '09 #17
ChipR
1,287 Expert 1GB
Turns out you can't really do DISTINCT on one column, because the db engine doesn't know which row to return. This is terrible, but you may have to do something like:

Union1
SELECT id, mod1 as modnum FROM table
UNION
SELECT id, mod2 as modnum FROM table WHERE mod2 NOT IN (SELECT mod1 FROM table)

Union2
Select id, modnum FROM Union1
UNION
Select id, mod3 as modnum FROM table WHERE mod3 NOT IN (SELECT modnum from Union1)
Aug 10 '09 #18
That didn't work. I'm still getting duplicates.
Aug 10 '09 #19
ChipR
1,287 Expert 1GB
Want to copy your SQL here and I'll look at it after lunch?
Aug 10 '09 #20
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, Modification_Number1 as modnum
  2. FROM [tbl:OASDHI]
  3. UNION
  4. SELECT ID, Modification_Number2 as modnum
  5. FROM [tbl:OASDHI]
  6. WHERE Modification_Number2 NOT IN (SELECT Modification_Number1 FROM [tbl:OASDHI]);
Aug 10 '09 #21
ChipR
1,287 Expert 1GB
Ah, I found the problem. The NOT IN works for the second part of the UNION, but the first SELECT still gives duplicates. The way around that is:
SELECT Min(ID), Modification_Number1 FROM OASDHI GROUP BY Modification_Number1
Aug 10 '09 #22
Here's the second union query I'm doing. I'm getting a parameter prompt for ID. I think it's because after I run the first query, instead of having ID as the header for the ID field, it is giving me an expr1000 header???

Expand|Select|Wrap|Line Numbers
  1. SELECT ID, modnum 
  2. FROM [qry:UnionModification1/2]
  3. UNION
  4. SELECT ID, Modification_Number3 as modnum
  5. FROM [tbl:OASDHI]
  6. WHERE Modification_Number3
  7. NOT IN
  8. (SELECT modnum FROM [qry:UnionModification1/2]);
Aug 10 '09 #23
ChipR
1,287 Expert 1GB
It sounds like it's making up a column header. If you're using the Min(ID) in the first query, make sure you assign your own like:
SELECT Min(ID) AS ID, ...
Aug 10 '09 #24
I tried that earlier and I get this message:
Circular reference caused by alias 'ID' in query definition's SELECT list.
. Here's the code I tried.

Expand|Select|Wrap|Line Numbers
  1. SELECT Min(ID) as ID, Modification_Number1 as modnum
  2. FROM [tbl:OASDHI]
  3. WHERE Modification_Number1 <> Null
  4. GROUP BY Modification_Number1
  5. UNION SELECT ID, Modification_Number2 as modnum 
  6. FROM [tbl:OASDHI] 
  7. WHERE Modification_Number2 NOT IN (SELECT Modification_Number1 FROM [tbl:OASDHI]);
Aug 10 '09 #25
ChipR
1,287 Expert 1GB
Try that same syntax but with the first GROUP BY query all by itself, then make a union using that query. I know it's an extra query, but it worked for me.
Aug 10 '09 #26
OldBirdman
675 512MB
I have been moving in this direction for some time, and been asking similar questions on this forum. The UNION queries kept getting worse, the problem more complex.

It is very simple to have a 2 column "SelectBox (listbox or combobox) to select by a name/title/desc field and use the hidden column to find the record and display it. There are a couple of methods for the display.

I can't post a solution at this time, but only express ideas until I get my own project working.

This is a database design problem. Having 3 "Entity Name" fields, some of which may be unused, is poor design. Moving just the alternate names to a separate table will help, but doesn't get rid of the UNION queries.

Move ALL the entity names to another table. This table at minimum needs 3 fields, Key, FK (Foreign Key), and Name. I also have a Type field, to keep track of whether this is Entity Name, or second ... or third ... SelectBox.ControlSource is now SELECT FK, Name FROM tEntityNames ORDER BY Name

If this list is very long, it can be easily filtered. A single CheckBox "Show All Names" could allow user to uncheck, adding a WHERE clause to the above WHERE Type=1 Other simple filters can be used.
Aug 10 '09 #27
ChipR
1,287 Expert 1GB
Good point OldBirdman. I assumed that this was a temporary fix, but really a redesign of the tables is required. It could be as simple as a Names table with entityID, Name, Type, where Type can be integer or string indicating primary, second, or third name option, or whatever.
Aug 10 '09 #28
OldBirdman
675 512MB
The tricky part is creating a new record. You create an entry in myTable and complete required entries. You cannot create the tEntityNames row yet, because you don't know the new PrimaryKey for myTable. If you save now, you have no tEntityNames name. If user goes to lunch now, this may become an orphan.

That is the part I'm working on now, but thought I would warn everyone before they leaped into it.
Aug 10 '09 #29
This is a temporary fix. The db isn't actually mine, this is just what the customer wants. They don't want to pull out the entity name into a separate table. Now, I got my first two queries to run just fine, but I'm running into a problem with my third one. It won't every stop running. I may just have to create the table and the customer is going to have to deal with it unless there's something I'm missing in the sql.
Expand|Select|Wrap|Line Numbers
  1. SELECT MinOfID, modnum
  2. FROM [qry:UnionModification1/2]
  3. UNION SELECT ID, Modification_Number3 as modnum 
  4. FROM [tbl:OASDHI] 
  5. WHERE Modification_Number3 
  6. NOT IN 
  7. (SELECT modnum FROM [qry:UnionModification1/2]);
Aug 10 '09 #30
ChipR
1,287 Expert 1GB
I use completely unbound forms for record entry, and I find that it's really not that much more work. I just wait for the user to hit Save, then I validate all the fields and copy their values into an SQL Insert statement (or 2). I do use bound forms for viewing records, but I haven't found a need to both view and enter records on the same form.
Aug 10 '09 #31
ChipR
1,287 Expert 1GB
Now it's a circular query reference, I guess. Here's what to do, assuming I didn't make any more silly mistakes:
Expand|Select|Wrap|Line Numbers
  1. 'qry1
  2. SELECT Min(ID) as ID, Modification_Number1 
  3. FROM OASDHI GROUP BY Modification_Number1
  4.  
  5. 'qry2
  6. SELECT ID, Modification_Number2 
  7. FROM OASDHI 
  8. WHERE Modification_Number2 NOT IN 
  9. (SELECT Modification_Number1 FROM OASDHI) 
  10.  
  11. 'qry3 
  12. SELECT ID, Modification_Number3 
  13. FROM OASDHI 
  14. WHERE Modification_Number3 NOT IN 
  15. (SELECT Modification_Number1 FROM OASDHI)
  16.  AND Modification_Number3 NOT IN 
  17. (SELECT Modification_Number2 FROM OASDHI)
  18.  
  19. 'union1
  20. SELECT ID, Modification_Number1 FROM qry1
  21. UNION
  22. SELECT ID, Modification_Number2 FROM qry2
  23. UNION
  24. SELECT ID, Modification_Number3 FROM qry3
Aug 10 '09 #32
OldBirdman
675 512MB
Yes, that is one way, if you don't need to enter multiple rows to the child tables when creating new entry. I only warned that this might not be a quick, EASY, fix, but another way to approach the problem.

stateemk has responded that he/she is going to continue with the 3 fields / one table, route.
Aug 10 '09 #33
Okay, I'm to a point where I'm stuck again. I have all the modification numbers from four columns combined into one using a union query. Now, my issue is when I use the query results as the drop box items in the form. The user wants to be able to select one modification number and have it pull up all the entities with that specific modification number no matter which column that modification number is in on the main table. Does this make sense?
Aug 11 '09 #34
ChipR
1,287 Expert 1GB
In this case, you don't really need the ID saved in the combo box, because you'll have to look them all up with a query anyway, so you can eliminate that column from the individual and union queries. Which means you can change that first query to just select distinct modification_number1 if you want.

Once a modification number is selected form the combo box, you'll list the results of a query like:
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, Modification_Number1, Modification_Number2, Modification_Number3 
  2. FROM OASDHI
  3. WHERE Modification_Number1 = Forms![myForm]!cmbModNumbers 
  4. OR Modification_Number2 = Forms![myForm]!cmbModNumbers 
  5. OR Modification_Number3 = Forms![myForm]!cmbModNumbers
Or you can use a query with a parameter rather than reference the control on the form, but I don't know the syntax for that offhand.
Aug 11 '09 #35
I do not know how to thank you enough for all your help ChipR. This is one of the first positive experiences I've had on a forum with reliable prompt answers. You've been a life saver for me. Thank you so much!!!
Aug 11 '09 #36
ChipR
1,287 Expert 1GB
Glad to help. I've learned so much from this particular forum, it's good to know I can return the favor sometimes.
Aug 11 '09 #37

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Emilio | last post by:
Hello everyone. I hope someone can help me with this. I have 3 columns called EMPLOYEE_TEST, TEST_QA and EMPLOYEE_TEST_ANSWER. The TEST_QA table contains the following: TEST_QA_ID |...
4
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
0
by: Arpan | last post by:
An ASP application needs to display DISTINCT records of all the columns existing in a SQL Server DB table in different drop-down lists. The column names & the no. of columns aren't known while...
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
7
by: teddysnips | last post by:
Table DDL below: The tables I have contain Timesheet information. Each row in the tblTSCollected table contains an entry for an employee into the timesheet system, specifically by scanning the...
3
by: newtophp2000 | last post by:
I have several forms that display information from the database after users log in. I would like the column titles to be sortable so that when the user clicks on a column heading, the data...
9
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
1
by: bluereign | last post by:
Thank you for your assistance. I am a novice looking to JOIN and append or combine records from 2 current Tables into 2 new Tables named below. I have been able to JOIN Tables with the script...
8
by: Sham | last post by:
I am trying to perform the following query on a table that has been indexed using Full Text Search. The table contains multiple columns than have been indexed. (Below, all xml columns are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.