473,545 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 "IssueCateg ory" 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
2 3027
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, strIssueCategor y as string
For Each varItm In lstIssueCategor y.ItemsSelected
strIssueCategor y = strIssueCategor y .ItemData(varIt m)
'do something
Next varItm

Nov 13 '05 #2
"jv" <ju***********@ hotmail.com> wrote in
news:11******** *************@g 49g2000cwa.goog legroups.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, strIssueCategor y as string
For Each varItm In lstIssueCategor y.ItemsSelected
strIssueCategor y = strIssueCategor y .ItemData(varIt m)
'do something
Next varItm


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

Dim varItm As Variant, strIssueCategor y as string
For Each varItm In lstIssueCategor y.ItemsSelected
strIssueCategor y = lstIssueCategor y.ItemData(varI tm)
'do something with strIssueCategor y
Next varItm

Dim varItm As Variant, strIssueCategor y as string
With lstIssueCategor y
For Each varItm In .ItemsSelected
strIssueCategor y = .ItemData(varIt m)
'do something with strIssueCategor y
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
10173
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the database table, using dynamic sql. Executing 'EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;' the error code -2149 is returned That means...
2
2009
by: Ellen Manning | last post by:
I'm developing an A2K adp that contains doctor info and the months they are not available for teaching. A doctor can be unavailable for some months for one year and other months for another year. I want the user to enter the year then use a multi-select list box to choose the months not available, then go to a fresh screen, enter another...
5
3245
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify this? Private Sub cmdPreview_Click() On Error GoTo Err_Handler 'Purpose: Open the report filtered to the items selected in the list box....
4
20994
by: devine | last post by:
Hi All, I am VERY new to Javascript. I have been provided with some code, which will enable me to hide/show a text area and change a submit button dependant on a check box. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3
1576
by: Tsurichan | last post by:
I understand there's another similar, if not identical question posted before. I have the same question but i don't really understand the solution. I'm doing this project for a school assignment. I have this code to list all the business number from the database: $res=mysql_query("SELECT business_no FROM customer_info"); for($i=0;...
4
3456
by: John | last post by:
Hello All, Can someone help me with a problem I am having? I have a form which has a multi-select list where the user can select more than one company name from a list and I need to pass those selections to a MySQL query for a report. The form is created in PHP. How do I get the list of items passed to my new page and include those
11
5577
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user can enter their search criteria eg. surname, reg num, etc. in the text boxes. The multi select list box allows the user to select multiple counties...
6
4655
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option for 2 list boxes:- county and nationality, while trying to add a third multi select list box for qualifications search is where i encounter my...
1
6776
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes bits of code for different examples. I have one last thing to finish. I am trying to create a search form that will allow users to select criteria from...
0
7486
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7932
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7442
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6001
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5347
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

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.