By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Delete row from a list box

100+
P: 434
I'm probably going about this the wrong way so any suggestions are appreciated.
I have a club data base with members I want to associate family members to a member. I created a associates table with the members club number, the associates club number, and the associates Name. I've created a combo box on the main members form where the user can select the associate and add it to the associates table, also on the main members form I have a list box where the associate members show up. This works fine, what I need to do is be able to double click on one of the associates and be able to go to that persons record or remove that associate from the list box. Because the associates member number is the second column in the Associates table and there can be multiple associates for any given member how do I find the correct associate to look up or remove.

I hope this is clear what I'm looking to do. If not let me know and I'll try again.
Jul 11 '12 #1
Share this Question
Share on Google+
4 Replies


zmbd
Expert Mod 5K+
P: 5,287
What is the primary key in the table? This is what you'll need to be able to remove the record.
-z
Jul 11 '12 #2

100+
P: 434
The primary key in the associates table is the main members clubmembernbr the associates number is the second in the table. There really isn't a primary key because there can be more than one associate assigned to the main club member. Is there a way to tell when you select a item from a list box what record we are pointing to? If I knew that then I could get the associates clubmembernbr and us it to either look up the record or delete it.
I hope this is a little clearer.
Jul 11 '12 #3

zmbd
Expert Mod 5K+
P: 5,287
One more question:

In one case you talk about a cmbobox where in the [associateclubnumber] is entered.
Then you have a list box with the [membersclubnumber]. Later in the post you talk about removing the [associateclubnumber] from the list box... do you mean the combobox? We also need to have an idea as to the data source for the combobox and listbox.

To handle finding the record you're interested in:

Without a primary-key , either as a single field within the table or as a composite key, you cannot ensure that you have a unique record.

So let's look at how we can determine how to locate your record.

For the sake of my sanity lets try something
Expand|Select|Wrap|Line Numbers
  1. [membersclubnumber] = 100 (for member 1)
  2. [membersclubnumber] = 200 (for member 2)
  3. [associateclubnumber] = 911 and [associatename] = john
  4. [associateclubnumber] = 912 and [associatename] = jane
  5. [associateclubnumber] = 921 and [associatename] = rob
  6. [associateclubnumber] = 922 and [associatename] = reba
Case 1 - this is what I expect your table to look like:
Expand|Select|Wrap|Line Numbers
  1. [membersclubnumber][associateclubnumber][associatename]
  2. [100][911][john]
  3. [100][912][jane]
  4. [200][921][rob]
  5. [200][922][reba]
Case 2 - however, without some logic to prevent duplications then you could get
Expand|Select|Wrap|Line Numbers
  1. [membersclubnumber][associateclubnumber][associatename]
  2. [100][911][john]
  3. [100][912][jane]
  4. [200][921][rob]
  5. [200][922][reba]
  6. [100][912][jane]
  7. [200][921][rob]
  8. [100][912][jane]
  9. [200][921][rob]
  10. [200][922][reba]
This is a mess. In order to prevent this, and even though I dislike them, I would use a composite primary-key against [membersclubnumber] and [associateclubnumber] this ensures that case 2 cannot happen. (if you use an autonumber field etc... you still risk case 2 without any logic to prevent it from happening) The only advantage to using the composite key is that it doesn't require any VBA/Macro code to prevent duplicate records... it does however, make the VBA code and SQL more difficult so I often add an indexed autonumber field to such tables... easy enough to find the record, pull the field's value... not really the best practice; however, a compromise I make for my sanity.

Now you only need to create a query that finds the record based on [membersclubnumber] and [associateclubnumber]. From there, there are several methods to edit the record (directly from the detail section of a form for one)... as for deleting the record, there's the delete query.

-z
Jul 11 '12 #4

100+
P: 434
After going over your comments I realize that the associates table is designed wrong. By making the Assoc mbr number the primary key everything works. There can only be one Associate member assigned to an individual member. By changing this everything works great. Thanks for your comments they helped.
Jul 11 '12 #5

Post your reply

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