> Ah interesting. I'd like to give users the option to not have to fill out
> everything. With this line, seems like they need to fill out all the
[quoted text clipped - 61 lines]
>>>>>>> Next
>>>>>>> ActiveDocument.Bookmarks("Activity2").Range.InsertBefore myString

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
When I add myString = Left(myString, Len(myString) - 1) after Next, I get an
error message that says "Run-time error 5, Invalid procedure call or
argument." Then when I switch to the VB screen, myString = Left(myString,
Len(myString) - 1) is highlighted.
This error occurs when I leave the listbox blank. When I remove myString =
Left(myString, Len(myString) - 1), then I do not get an error when I leave
the listbox blank. What is the reason for this? I've provided more of my code
below, for your reference. Thanks so much for your assistance! Amy
My code is:
Private Sub CommandButton1_Click()
Dim i As Long
Dim myString As String
With ActiveDocument
For i = 1 To Activity1.ListCount
If Activity1.Selected(i - 1) Then
myString = myString & Activity1.List(i - 1) & vbCrLf
End If
Next
myString = Left(myString, Len(myString) - 1)
ActiveDocument.Bookmarks("Activity1").Range.InsertBefore myString
myString = ""
For i = 1 To Activity2.ListCount
If Activity2.Selected(i - 1) Then
myString = myString & Activity2.List(i - 1) & vbCrLf
End If
Next
myString = Left(myString, Len(myString) - 1)
ActiveDocument.Bookmarks("Activity2").Range.InsertBefore myString
myString = ""
End With
Me.Hide
End Sub
> Amy,
> The code snippet that you have shown is apparently inserting selected
[quoted text clipped - 79 lines]
> >>>>>>> Next
> >>>>>>> ActiveDocument.Bookmarks("Activity2").Range.InsertBefore myString
Russ - 31 Jul 2007 18:22 GMT
Encapsulate that line with an empty string check.
If Not myString = "" then
myString = Left(myString, Len(myString) - 1)
End If
> When I add myString = Left(myString, Len(myString) - 1) after Next, I get an
> error message that says "Run-time error 5, Invalid procedure call or
[quoted text clipped - 125 lines]
>>>>>>>>> Next
>>>>>>>>> ActiveDocument.Bookmarks("Activity2").Range.InsertBefore myString

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ - 31 Jul 2007 18:27 GMT
I think you get an error because with an empty string the Len (or length) is
zero, then trying to subtract a 1 to get rid of a trailing paragraph mark
gives a -1, which the Left() function does not expect, it wants positive
numbers.
> When I add myString = Left(myString, Len(myString) - 1) after Next, I get an
> error message that says "Run-time error 5, Invalid procedure call or
[quoted text clipped - 125 lines]
>>>>>>>>> Next
>>>>>>>>> ActiveDocument.Bookmarks("Activity2").Range.InsertBefore myString

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID