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

Problem Using "Multi Select" Feature with a List Box on a Form

P: n/a
Hello everyone,
I am having an issue using the "Multi Select" option in a list box
in MS Access 2003. I am making a form that users can fill out to add
an issue to the database. Each issue can be associated with multiple
categories. I have an "Issue," "IssueCategory," and
"Category" in the database (among other tables). The form has a
subform in it which is tied to the "IssueCategory" table. The main
form is tied to the "Issue" table. Right now I am able to create
an issue and select multiple categories for one issue. I have to use
the buttons at the bottom of the form to add each individual category
for each issue. I would like to use the "Multi Select" feature so
that I can remove the buttons at the bottom of the subform and user's
will not have to add each category individually, they can just select
all the applicable ones directly from the single list box. When I set
the list box to simple multi select and try to use it in a way that I
just described I get the following error: "Index or primary key
cannot contain a Null value." I get this error regardless of the
number of categories I select. If I select any amount and then
deselect them all I will get this error again. When I don't select
any categories (at all) then I can create a new issue without getting
an error, but each issue must have at least one category. How can I
use the multi select feature and have it add the primary key of the
Issue table to the IssueCategory table for each selection in the list
box (when using the multi select)? Thank you very much for your help,
any tips are appreciated.

- Michael

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
jv
You will have to iterate through the listbox's ItemsSelected collection
to get each of the selected issue categories.

Sample code:
Dim varItm As Variant, strIssueCategory as string
For Each varItm In lstIssueCategory.ItemsSelected
strIssueCategory = strIssueCategory .ItemData(varItm)
'do something
Next varItm

Nov 13 '05 #2

P: n/a
"jv" <ju***********@hotmail.com> wrote in
news:11*********************@g49g2000cwa.googlegro ups.com:
You will have to iterate through the listbox's ItemsSelected
collection to get each of the selected issue categories.

Sample code:
Dim varItm As Variant, strIssueCategory as string
For Each varItm In lstIssueCategory.ItemsSelected
strIssueCategory = strIssueCategory .ItemData(varItm)
'do something
Next varItm


That needs to be changed to one of these two versions in order to
work:

Dim varItm As Variant, strIssueCategory as string
For Each varItm In lstIssueCategory.ItemsSelected
strIssueCategory = lstIssueCategory.ItemData(varItm)
'do something with strIssueCategory
Next varItm

Dim varItm As Variant, strIssueCategory as string
With lstIssueCategory
For Each varItm In .ItemsSelected
strIssueCategory = .ItemData(varItm)
'do something with strIssueCategory
Next varItm
End With

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.