+ Reply to Thread
Results 1 to 4 of 4

Can only read value from *some* listboxes

Hybrid View

mexindian Can only read value from... 04-09-2013, 06:44 AM
MickG Re: Can only read value from... 04-09-2013, 08:40 AM
mexindian Re: Can only read value from... 04-09-2013, 08:56 AM
MickG Re: Can only read value from... 04-09-2013, 08:59 AM
  1. #1
    Registered User
    Join Date
    08-27-2012
    Location
    Roma, Italia
    MS-Off Ver
    Excel 2003
    Posts
    60

    Angry Can only read value from *some* listboxes

    So I have a form that simplifies the process of entering in systematic information. The form consists of 3 listboxes, a textbox and a few buttons. It works fine if the user clicks on each listbox, and then on the "OK" button.

    I also want to provide a radiobutton that pre-populates each control (there's basically one combination that's popular, so the radiobutton saves time and maximizes consistency). All the controls get properly selected..... but I can only get values from 2 of the listboxes... one of them only gets a value if a user CLICKS on it... otherwise it keeps value=""

    No multi-select issues or complex stuff... this should be super simple... What gives?

    Probably easiest to understand if you look at the file HERE: bug.xls

    CODE BELOW:

    Option Explicit
    
    Private Sub CommandButton1_Click()
        ActiveCell.Value = _
        Left(Me.ListBox1.Value, 1) & _
        Left(Me.ListBox3.Value, 1) & _
        Left(Me.ListBox2.Value, 1) & "|" & _
        Me.TextBox1.Value
    Unload Me
    End Sub
    
    Private Sub OptionButton1_Click()
    
        Me.ListBox1.ListIndex = 2
        Me.ListBox2.ListIndex = 0
        Me.ListBox3.ListIndex = 1
        Me.TextBox1.Value = "TEST"
        Me.CommandButton1.SetFocus
    End Sub
    
    Private Sub userform_activate()
        With Me.ListBox1
            .AddItem "A1"
            .AddItem "B2"
            .AddItem "C3"
        End With
        With Me.ListBox2
            .AddItem "Y"
            .AddItem "N"
        End With
        With Me.ListBox3
            .AddItem "1 "
            .AddItem "2 "
            .AddItem "3 "
        End With
    End Sub
    Last edited by mexindian; 04-09-2013 at 06:46 AM. Reason: removing duplicate attachment

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Can only read value from *some* listboxes

    In your Option button code , Use the "SetFocus" method. It worked for me !!!
    Something like this:-
    Private Sub OptionButton1_Click()
    
    ListBox1.SetFocus
    ListBox1.ListIndex = 0
    
    ListBox2.SetFocus
    ListBox2.ListIndex = 1
    
    ListBox3.SetFocus
    ListBox3.ListIndex = 2
    End Sub

  3. #3
    Registered User
    Join Date
    08-27-2012
    Location
    Roma, Italia
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: Can only read value from *some* listboxes

    Outstanding. Solved it! Thanks so much! (let's not talk about WHY THAT IS REQUIRED..... GRRRRRRRRRRRRR)... but let's be grateful that it's solved!

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Can only read value from *some* listboxes

    Your welcome
    regrds Mick

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1