Email help with ListBox

S

Stockwell43

Hello,

I downloaded the emailsenate2k database from this site:

http://www.datastrat.com/DataStrat2.html

If I make a selection in the email address and click the email button it
works fine. When I de-selected the email address I get an error. My concern
is that the user my make a selection then decide that was the wrong email
address and de-select and get this error and I don't want this to pop up
because I don't want them to mess with anything. Any help would be
appreciated.

Here is the error I get:

Run-Time Error '5': Invalid procedure call or argument
In the code below, this is what is highlighted in yellow:

strList = Left$(strList, Len(strList) - 1)

And this is the code behind the click enevet in the list box:

Private Sub lstMailTo_Click()
Dim varItem As Variant
Dim strList As String

With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
strList = Left$(strList, Len(strList) - 1)
Me!txtSelected = strList
End If
End With
End Sub
 
K

Ken Sheridan

Examine the Count property of the list box's ItemsSelected collection to see
if any items are selected. Try this:

Private Sub lstMailTo_Click()

Dim varItem As Variant
Dim strList As String

With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
If .ItemsSelected.Count > 0 Then
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
strList = Left$(strList, Len(strList) - 1)
End If
Me!txtSelected = strList
End If
End With

End Sub

I must say that I'm not over-impressed with this code. Examining the Count
property before looping through a list box's ItemsSelected collection is
routine and something which the original developer of this application should
have done. Also there is no error handling, which in a distributed
application is not good.

Ken Sheridan
Stafford, England
 
S

Stockwell43

Hi Ken,

That did the trick!

Your help was greatly appreciated. Thank you and have a great weekend!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top