Advertisement

02.05.2008 at 12:31PM PST, ID: 23139270
[x]
Attachment Details

Access: Multi-Select list box populates multiple rows in table

Asked by noahisaac in Access Forms, Microsoft Access Database, Access Coding/Macros

Tags: Access, N/A, N/A

Hi -

I'm not so good with Access/VBA and need some help.  I have a form that has a combo-box and a multi-select list box.  I'd like the selected items on that combo box and list box to each be inserted into separate records in a table.  For example:

Combo Box: SandwichName
List Box: SandwichIngredients

A form entry might look like:
Combo Box: Ham Sandwich
List Box:  Bread      [Selected]
                Ham         [Selected]
                Turkey    
                Mayo       [Selected]
                Mustard
                Cheese


And I'd like the resulting "Sandwiches" table to look like:

Name                         Ingredients
Ham Sandwich          Bread
Ham Sandwich          Ham
Ham Sandwich          Mayo  


I think I need some VB code to do this.  I found a code snippet elsewhere on EE that I thought might do the trick.  I adapted it a little, and I tried putting this into the Click() sub for the list box "List4":

    Dim i As Integer
    Dim sSql As String

    For i = 0 To List4.ListCount - 1
        If List4.Selected(i) = True Then
            sSql = "INSERT INTO Sandwiches (Name, Ingredients) VALUES (SandwichName,SandwichIngredients)"
            Debug.Print sSql   'diagnostic
            CurrentDb.Execute sSql, dbFailOnError
        End If
    Next i


No dice.  At run time I get an error message that says I don't have enough parameters, that it was expecting two parameters.


Thanks for your help!
NoahStart Free Trial
 
 
Loading Advertisement...
 
[+][-]02.05.2008 at 12:44PM PST, ID: 20826722

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Forms, Microsoft Access Database, Access Coding/Macros
Tags: Access, N/A, N/A
Sign Up Now!
Solution Provided By: capricorn1
Participating Experts: 3
Solution Grade: A
 
 
[+][-]02.05.2008 at 01:16PM PST, ID: 20827080

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.05.2008 at 01:18PM PST, ID: 20827102

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.05.2008 at 01:19PM PST, ID: 20827130

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.05.2008 at 01:37PM PST, ID: 20827307

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 06:35PM PST, ID: 21000759

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628