+ Reply to Thread
Results 1 to 5 of 5

User Form Combo Box Input/Value Source

  1. #1
    Registered User
    Join Date
    04-29-2013
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    21

    User Form Combo Box Input/Value Source

    Hi all

    I have created a user form to create, save, edit and delete records to/from an Excel database. It has 2 combo boxes (combo 1 and combo 2). Combo 2 drop down list is dependent on the selection in combo 1. They both use dynamic named ranges for their lists and allow manual user input as well as selection from the drop down list.

    When the form is used to read a record from the database, the 2 combo boxes are populated with the data in the record. I need to set the drop down list in combo 2 based on the value in combo 1 ie - I need to determine if combo 1 value was selected from the drop down list or manual user input. I can't use the index value when the record is first populated, as it it <-1 even if the value was originally selected from the list.

    What is the best way to determine if combo 1 value is from the combo list or not?

    As I am relatively new to coding, I am hoping for a simple answer

    Thanks

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    If the value isn't on the list then the ListIndex will be -1, the ListIndex can't be less than -1.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-29-2013
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: User Form Combo Box Input/Value Source

    OK - my mistake. The ListIndex = -1. When the record was originally created, if the selection was from the drop down list, ListIndex > -1. The problem seems to be the process of saving it to the database and then re-reading the record; the ListIndex is 'reset' to -1.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: User Form Combo Box Input/Value Source

    Jane

    Is this when you are entering a new value in the combobox?

    Are you updating the combobox's list after you've added the data to the worksheet?

  5. #5
    Registered User
    Join Date
    04-29-2013
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: User Form Combo Box Input/Value Source

    Hi Norie

    your comment re 'if the value isn't on the list, then the ListIndex will be -1' got me thinking about the relative timing of the code ie - was i populating the combo box value before populating the combo box list? And this was exactly the problem. I changed the code order to set the combo box list first and then set the combo box value. Problem fixed.

    Thanks for your tip.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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