+ Reply to Thread
Results 1 to 23 of 23

Combo Box additions not showing until after Userform closes and is reopened.

  1. #1
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Combo Box additions not showing until after Userform closes and is reopened.

    I have a multi-page UserForm in Excel and after I entered a name into a ComboBox and it's related fields, I then press a button to add/update that information to an underlying worksheet called 'CandidateData', next I proceed with entering the next name into the ComboBox and so on. But, I found as I tested this process that I cannot find the names of those candidates I have just entered within the combobox drop down arrow - the names are not there. But, when I closed the UserForm to see if the candidates were in the CandidateData worksheet, they were there.

    When I reopened the UserForm, I could then see the names of all three candidates entered in the ComboBox drop down. Then, when I add yet another name or two those new names are still not shown in the drop down of the Combobox, while the ones previously entered are seen. The new one's won't be seen until I close the UserForm and re-open it.

    How can I fix this so they will be seen without having to close the UserForm?

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

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Why would the names be there?

    They aren't getting added to the combobox, they are getting added to the sheet.

    If you want you could update the combobox with the code used to populate it in the listbox.

    Just copy the 3 lines that do that and paste them at the end of the code to add a new candidate.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    When they are added to the sheet, the user is supposed to be able to use the drop down arrow of the combobox to re-select their desired candidates if needed.

    I'm looking for the code that populates it into the listbox, but where is it? I'm assuming its under the frmPrintCand.... is it this code?

    Please Login or Register  to view this content.

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

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    The code is in the userform Initialize event, that code has nothing to do with it - it doesnt' even refer to the combobox.

    Off the top of my head it looks something like this.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Alright. I have added these three lines, having copied them from elsewhere, to the bottom of the code for the Add/Update command button.... just before End Sub. When I tested it I got an error: Runt-Time Error '424': Object required, and it pointed me to this line of code:

    Please Login or Register  to view this content.

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

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Isn't this line of code from the print form?
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Yes, that is what you had put up above, the 3 lines of code to copy over. The three lines of code that pupulat the listbox.

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

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    That is not one of the lines I meant.

    lstCandidates is a control on the print form, not the main form.

    Code that refers to that control should not be in the main form.

  9. #9
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    You had said to

    [quote]
    If you want you could update the combobox with the code used to populate it in the listbox
    [/quote}

    What other code populates this information in the listbox?

    When I search in the IntvwWorksheet I find the following that mentions cboCandidate:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    And under the Add/Update I find:

    Please Login or Register  to view this content.
    But, I don't think that one is it.

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

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    That was a typo.

    What you need to do is add the code to populate the combobox at the end of the code that add's a new candidate to the worksheet.

    These are the lines of code that populate the combobox.
    Please Login or Register  to view this content.
    The If was added to take care of there only being one canidate.

    What I suggest you do is this.

    Create a new sub called PopCandidateCombo in the userform module.

    Paste the above code into the sub.
    Please Login or Register  to view this content.
    Now change the userform Initialize event code to this which calls the new sub.
    Please Login or Register  to view this content.
    At the end of the code to add a new candidate add this.
    Please Login or Register  to view this content.
    Now when you add a new candidate the combobox should get updated.

  11. #11
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Yay! I think it worked just fine. I'll test it a few more times. I want to clarify, I added 'Call PopCandidateCombo' to the end of the userform Initialize event code. Thank you once again for your help!

  12. #12
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Yes! It's working. Thank you

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

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    No you don't add it to the end of the code, you replace the exisiting code with it.

    If you just add it at the end of the existing code you'll be populating the combobox twice.

  14. #14
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Good to know. Thank you. I will do that. And, it seems to be working just find, too. Thanks again

  15. #15
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    I just realized that by removing this code from the UserForm_Initialize ()

    Please Login or Register  to view this content.

    That, it reverted me back to this problem with the Run-Time Error '381'.

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

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    I'm not sure I understand. Why did you remove that code?

    You need that code to populate the candidate combobox.
    Last edited by Norie; 12-20-2012 at 04:26 AM.

  17. #17
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Quote Originally Posted by Norie View Post
    No you don't add it to the end of the code, you replace the exisiting code with it.

    If you just add it at the end of the existing code you'll be populating the combobox twice.
    That is why I replaced it, but the code I removed was intended to allow only one candidate to be entered and still work when printed. However, re-adding that code into the Initalize event isn't solving the problem. My debugging is highlighting the Private Sub UserForm_Initialize (). Here is the entire code:

    Please Login or Register  to view this content.
    What has gone wrong?

  18. #18
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Okay, it looks like I had too many End Subs with that particular code. But, I still cannot print when there is only one single candidate. This time I was given the Run-Time Error '381': Could not set the List Property. Invalid Property Array Index. Debugging hilighted "lstCandidates.List = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Value" under the following code found in the print userform:

    Please Login or Register  to view this content.
    But, this is what happened last time and we had had it fixed - see thread: http://www.excelforum.com/excel-prog...ray-index.html

  19. #19
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    I'm wondering if that code needs to go into that intialize event under the print userform that I just provided in the last post?

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    First you need to delete this code from the main form's Initialize event.
    Please Login or Register  to view this content.
    This calls the sub PopCandidateCombo which populates the combobox.
    Please Login or Register  to view this content.
    All you need in the main form's Initialize event is that line of code and the code to populate the first two pages.


    By the way, this isn't quite right:
    'placed here so ComboBox additions will show without having to close Userform.
    The combobox is updated when a new candidate is added by calling PopCandidateCombo again.

    Also, this code has nothing to do with printing or the print form.

    The problem with the print form when there is only one candidate is the same as there was with the combobox on the main form.

    To fix the print form we can use similar code to that we used for the main form.

  21. #21
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Great! This is what I have for the frmPrintCand Initialize event:

    Please Login or Register  to view this content.

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

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    That looks about right, does it work?

  23. #23
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: Combo Box additions not showing until after Userform closes and is reopened.

    Yes, it appears to be working

+ 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