Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jun 2002
    Location
    Johannesburg, Gauteng, South Africa
    Posts
    59
    Thanks
    2
    Thanked 0 Times in 0 Posts

    UserForm Drop down list box (2000 SR-1)

    Hi, I hope someone can help me. I have managed to populate the list box as detailed in this post - <post#=302680>post 302680</post#> . One problem. If the user clicks the OK (Commandbutton1) button without making a selection, a number of spaces (depending on the number of columns) are inserted at the bookmark. I want to force the user to make a selection or abort the insertion. How would I go about this? Thank you..

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: UserForm Drop down list box (2000 SR-1)

    You could modify the CommandButton1_Click routine to check what listbox1.Value is and if it is -1 (I think this is the unselected state, you will need to check) then just Exit Sub. You could even display a message box first telling the user that they have to select a value before clicking OK.

    Something like this (completely untested)...
    <font face="Georgia">
    Private Sub CommandButton1_Click()
    Dim i As Integer, Addressee As String

    if ListBox1.Value = -1 then
    MsgBox "You must select a value before clicking OK", vbExclamation
    Exit Sub
    End If

    Addressee = ""
    For i = 1 To ListBox1.ColumnCount
    ListBox1.BoundColumn = i
    Addressee = Addressee & ListBox1.Value & vbCr
    Next i
    ActiveDocument.Bookmarks("Addressee").Range.Insert After Addressee
    UserForm2.Hide
    End Sub
    </font face=georgia>
    StuartR

    PS You could have added a new post to your existing thread, this might help people follow the discussion more easily.

  3. #3
    Star Lounger
    Join Date
    Jun 2002
    Location
    Johannesburg, Gauteng, South Africa
    Posts
    59
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: UserForm Drop down list box (2000 SR-1)

    Thanks Stuart - could not get it to work using ".Value". Did a bit of searching on help and found ".ListIndex".

    if ListBox1.ListIndex = -1 then
    MsgBox "You must select a value before clicking OK", vbExclamation
    Exit Sub
    End If

    This works like a charm. Thanks again

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: UserForm Drop down list box (2000 SR-1)

    > could not get it to work using ".Value". Did a bit of searching on help and found ".ListIndex"

    Thanks for posting the correction
    That's what happens when I post quickly whilst drinking my early morning coffee before going to work <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    StuartR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •