Data Entry with mult-select listbox??

K

Kevin Buchanan

I am using a mult-select listbox to select several rows. I would like to add
them to a table that is part of a one-to-many relationship with the "master"
table.

I have tried, but haven't found any "out-of-the-box" functionality to allow
this; I assume it will take VBA code?
 
A

Allen Browne

Yes. It it take quite a bit of code to load the list box in the Current
event of the form, dirty the form whenever there is any change in the
unbound listbox, and loop through the ItemsSelected collection, and write
and insert/delete the new/removed items from the multiselect list box
into/from the related table without duplicating them in the form's
BeforeUpdate event.

It is much simpler to use a subform where the user can use a combo box to
enter as many related row as needed.
 
K

Kevin Buchanan

2 questions:

How do you "dirty the form" (and check for it's 'dirtiness'?) :)

How does the subreport "tie" to the main form's Primary key? I tried to
create a subreport, but I could find the relationship to the Main Form
table's primary key.

Thanks!!
 
A

Allen Browne

You can dirty the form by changing the value of any bound control - even if
you change it to the same value it was. For example:
Me.City = Me.City

Test the Dirty property of the form, e.g.:
If Me.Dirty Then ...

The form's BeforeUpdate event fires if the form is dirty, so you can use
this event to write the data.

A subreport control's linke to the data in the main report is through its
LinkMasterFields and LinkChildFields properties.
 
K

Kevin Buchanan

Thanks - that did it! I had started saving the records by looping through
the selected items collection - but that was TEDIOUS. This will save a LOT
of coding!

Thanks so much!
 
Top