List box please help

  • Thread starter Thread starter Dib
  • Start date Start date
D

Dib

Hi again,

I was able to figure out how to add

If varItm = 0 Then
Me.lstAttachments.RowSource = sFile
varItm = 1
Else
Me.lstAttachments.RowSource = Me.lstAttachments.RowSource & ";" &
sFile
End If

Now I need help with how to remove an item if the user select to remove ,

Please advice

Thanks
Dib
 
Hi,
Here is a function that will remove a word from a list (that is delimited in some way).
Place it in a standard module.

Public Function RemoveItemFromList(strIn As String, strItem As String) As String
Dim str1 As String
Dim str2 As String

str1 = Left(strIn, InStr(1, strIn, strItem, vbTextCompare) - 1)
str2 = Mid(strIn, InStr(1, strIn, strItem, vbTextCompare) + Len(strItem) + 1)
If right(str1, 1) = ";" Then
str1 = Left(str1, Len(str1) - 1)
End If
RemoveItemFromList = str1 & str2
End Function

Use it like this:
Me.lstAttachments.RowSource = RemoveItemFromList(Me.lstAttachments.RowSource,sFile)

Make sure you add error handling either to the function or in the calling routine!
 
thanks for the function .

it works great with two items in the list box but if I add up to 4 items
(Values) it return an invalid procedure call. is the error trap for this
kind of error or do I need
to modify the function so that it works with the number of records.

Thanks
Dib
 
I got it.
it was the sFile , it was not refreshing when you delete one item, so when I
select another item to delete the sFile value is the old deleted item which
does not exists.
so I Dim sFile only to the command button instead of being golbal and it
worked.

Thanks
Dib
 
Back
Top