Whose click event is this? Every selection you make in the listbox
accounts for one click, which may cause the data you see.
I suggest you put a button next to the listbox, caption "Update" or so
(find something that matches what happens as exactly as possible).
Even the Exit event of the listbox is unreliable, unless you start the
procedure by removing all previous entries from the table.
As for clearing all selections (which I'd rather hesitate to judge
'secondary'):
inside the loop, after you've done the INSERT, do
ctl.selected(varitem)=false
Oh by the way: your frm and ctl references are completely superfluous.
"Category" would do. I suggest you name it ctlCategory, though, or even
lstCategory, that tells you from viewing the code what is going on.
google@myxware.com wrote:
[color=blue]
> Ok, I have the data outputting into the table into separate rows.
> The problem is that it does not put one entry per selection. For
> example if I select item 3 and item 5 in the list box I get 3, blank,
> 3, and 5 in separate rows (in that order). Is it possible for me to
> get just a 3 in one row and 5 in the next.
> A secondary issue is when I am selecting the data in the listbox and
> I move onto a new entry set I have to deselect the items I do not want
> (that were selected in the previous entry set). Is there some way
> that I can clear the selections in the listbox for each entry set?
> Thanks.
>
> Here is my latest code:
>
> Private Sub Category_Click()
>
> Dim frm As Form, ctl As Control
> Dim varItem As Variant
> Dim strSQL As String
> Set frm = Me
> Set ctl = frm!Category
> For Each varItem In ctl.ItemsSelected
>
> CurrentDb.Execute "INSERT INTO tblCategoryTest
> (SelectedCategories) VALUES('" & ctl.ItemData(varItem) & "')"
>
> Next varItem
>
> Me.catText.Value = Me.Category.ItemsSelected.Count
> Me.catText2.Value = strSQL
> End Sub
>
> - Michael
>[/color]
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html