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]
And I'd like the resulting "Sandwiches" table to look like:
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
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!