+ Reply to Thread
Results 1 to 8 of 8

Userform ComboBox - Retain Value

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Userform ComboBox - Retain Value

    Hi, short story is I need to retain the value in the ComboOffice box (until it's changed) and I'm getting confused and going in circles

    Long story:
    Userform (frmInput) with ComboOffice - the values for the combo are loaded on workbook open and don't change.

    The form loads on workbook open.
    The user is to pick an office from the first combobox, the value returned is the 2nd column, which is a number. (so user sees name in box, value is number)
    (This is all working)

    The user then picks 1 of 3 option buttons.
    button 1 shows ComboNames and loads manager names to ComboNames
    button 2 shows ComboNames and loads worker names to ComboNames
    button 3 doesn't show ComboNames at all

    Then user clicks command button (frmButton1)
    (there is error handling if they don't pick a button)
    it pulls the data and hides the form (frmInput.Hide)
    (because I only hide and don't unload, I thought it would retain value and this is confusing me, too)

    There is a command button (cbReloadfrmInput) on the worksheet where the data is placed that allows user to show form and make a different selection. Generally user will only change names and not office.

    The ComboOffice continues to show the name of the office that was previously chosen (because I don't clear it), but the office value is now gone. I'd like to retain and continue to use the same value until they make another choice. But I'm confused on where I store that value and when I need to call it.

    There is a change event for ComboOffice, and click events for each button.

    The value is used as a parameter in SQL query and the first time it's picked no problem, but then value is lost and so am I.
    Last edited by ker9; 10-19-2010 at 11:11 AM.

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Userform ComboBox - Retain Value

    It might be easier if you posted a sample of your workbook (sensitive data removed) to help us identify the problem. If you can, load in .xls format, as I don't have Office 2007 at the workplace.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userform ComboBox - Retain Value

    Hiding the form should not clear the selections. Can you upload the workbook
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Userform ComboBox - Retain Value

    At the very least I think we'd need clarification of this bit: "the values for the combo are loaded on workbook open" and the code for the button that reloads the form.
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Userform ComboBox - Retain Value

    There is a lot that would need to be removed in order to post the workbook. I'll try providing code and see if that helps make it clearer.

    Workbook Open
    Please Login or Register  to view this content.
    SHOW FORM
    Please Login or Register  to view this content.
    FORM CODE
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Userform ComboBox - Retain Value

    I am testing form -
    I select office, click partner button and then command button- OK
    Reload form, the office name previously selected is still in the ComboOffice box - everything OK
    Reload form (2nd reload), office name is cleared and so is the value from the sheet
    I can't figure out where it's getting cleared - I dont' see any code that it doing that.

    I want to retain the office name in the box and the number on the sheet until user changes it

    I maybe don't understand load and unload?

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Userform ComboBox - Retain Value

    Your button that reshows the form also resets the list for no apparent reason - that is why the value is lost.

  8. #8
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Userform ComboBox - Retain Value

    THANK YOU !! I looked at that code so much I just couldn't see what was right in front of me.
    I can't believe it was that simple.
    Thank you!

+ 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