473,406 Members | 2,336 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,406 software developers and data experts.

Remove items from combo list when used

I have a combo box on a details subform with 8 items in the list. Each item should be used once for each record on the main form. Is there a way to remove an item from the available choices when it has been used and if so how?
Thanks!
Oct 5 '11 #1
9 2023
nico5038
3,080 Expert 2GB
Looks to me you need to use the EXISTS clause in the combo's WHERE clause to detect or the combo's value has been used for the Mainform's record.
Assuming the Main form holds a Person with a PersonID it would look like:
Expand|Select|Wrap|Line Numbers
  1. select subcode from tblPersonSub where not exists (select subcode from tblPersonSub where PersonID = forms!main!personid)
getting the idea ?

Nic;o)
Oct 6 '11 #2
I think I understand what you're talking about. I've created the subquery which returns the correct records when ran independantly. When I transferred this query to the criteria of the combo's rowsource query and viewed these results, none of the items were eliminated.
Here is the subquery code:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTireService.TirePositionID
  2. FROM tblTireService
  3. WHERE (((tblTireService.ServiceDetailsID)=[me].[serviceDetailsID]));
This returns "1,2,3" which is correct.
Here is the rowsource query with the subquery criteria:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTirePosition.TirePositionID, tblTirePosition.TirePosition
  2. FROM tblTirePosition
  3. WHERE ((Not (tblTirePosition.TirePositionID)=Exists (SELECT tblTireService.TirePositionID
  4. FROM tblTireService
  5. WHERE (((tblTireService.ServiceDetailsID)=[me].[serviceDetailsID]));)));
This returns "1,2,3,4,5,6,7,8,9,10".
Why is it not eliminating "1,2,3"?
Thanks!
Oct 6 '11 #3
nico5038
3,080 Expert 2GB
The use of the "Me." doesn't work in the combo's rowsource, you should refer to the form by name like:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTirePosition.TirePositionID, tblTirePosition.TirePosition
  2. FROM tblTirePosition
  3. WHERE NOT Exists (SELECT tblTireService.TirePositionID
  4.                   FROM tblTireService
  5. WHERE tblTireService.ServiceDetailsID=[forms]![frmFormName]![serviceDetailsID]);
  6.  
I've also removed the comparison, as the "NOT EXISTS" is enough.

The "Me." can be used when you "string" the SQL statement and assign it to the Me.combo in code.

Nic;o)
Oct 6 '11 #4
I pasted your SQL into the query window, supplied the variable and it returned no records.
Thanks!
Oct 6 '11 #5
nico5038
3,080 Expert 2GB
Hmm, confused, was this the result expected or not ?

Nic;o)
Oct 6 '11 #6
the result should have been "4,5,6,7,8,9,10"
Oct 6 '11 #7
nico5038
3,080 Expert 2GB
OK, guessed already that the used key was the wrong one, switch in the EXISTS clause ServiceDetailsID with TirePositionID as you need the ServiceDetails not found in the relation table for the "master" key.

Nic;o)
Oct 6 '11 #8
That's not sounding right to me. This ServiceDetailsID should have 10 TireServiceID (detail)records with one TirePositionID for each record. Currently there are 3 detail records for this ServiceDetailsID - "1,2,3". The EXISTS clause needs to find the TirePositionID's that have been used with this ServiceDetailsID to remove them from the complete list. Your suggestion, as I understand it would be looking for the ServiceDetailsID in tblTireService which would be the same for all the records.
Oct 6 '11 #9
nico5038
3,080 Expert 2GB
Hmm, it's a handicap not knowing the table structure, but the general idea is:
1) The combo's source table needs to hold all values (1 to 10)
2) The WHERE NOT EXISTS needs to find the used values from this range in the relation table.

So I would start with checking the SELECT in the WHERE NOT EXISTS clause to see or 1,2,3 are returned. Just use it as the combo's rowsource.

Nic;o)
Oct 6 '11 #10

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

Similar topics

23
by: Stan Cook | last post by:
I was trying to take a list of files in a directory and remove all but the ".dbf" files. I used the following to try to remove the items, but they would not remove. Any help would be greatly...
0
by: Shawn K | last post by:
I populate a listbox with the following code when my form loads: lstBox.Items.Add("value"); Once the page loads, I give the user the ability to remove items from the list box by selecting an...
1
by: bbcdancer | last post by:
Is it possible to restrict the length of a text box in MS Access using VBA on condition to what is selected in a list combo box. Scenario: 1. I have a list combo box containing: AA BBB...
10
by: pamelafluente | last post by:
Hi I have a sorted list with several thousands items. In my case, but this is not important, objects are stored only in Keys, Values are all Nothing. Several of the stored objects (might be a...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
2
by: Lit | last post by:
Hi, what is the best way of removing multiple items from a list box found in another list box. Foreach does not allow you to modify itself Looping through has index issues. Other than...
11
by: calred | last post by:
i am trying to remove items in a list if the items do not exist in another list but my program does not work the way i have expected for example: l = l2 = # l2 could be a list of raw...
2
by: sanguinechris | last post by:
I'm trying to create a form that has States and it's local governments, such that when I select a state in a combo list, then in the next combo list, all it's local governments are displayed so I can...
20
by: MarkP | last post by:
Hello, I have a combo box that feeds a list box1 which in turn feed another list box2. List box2 values need to remain in list box2 when list box1 has been change by the combo. The content of list...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.