+ Reply to Thread
Results 1 to 15 of 15

Autofill TextBox on each page of Multipage Userform

  1. #1
    Registered User
    Join Date
    02-10-2011
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    12

    Autofill TextBox on each page of Multipage Userform

    Hi All,

    I am still pretty much an amateur to all this VBA stuff, and would be most grateful for some guidance on writing a bit of elegant code, rather than the very long winded way I have done it.

    I have two UserForms, Projectdetails and Criteria. A user will complete the various parts of the first form "Project Details" and click contiue to go to the second form "Criteria".

    Criteria is a multipage userform with the first page being checkboxes to select up to eleven countries, each having their own page within the multipage form.

    I have made the country pages visible / hidden accordingto the selection on the first page, and am just starting on pre-filling a couple of text boxes on each page as an aide memoir, but before I go through typing blah blah Pages(1) blah, blah blah Pages(2) etc, I wondered is anyone could suggest a way of writing it more elegantly and the same with the hide/ unhide pages.

    My code so far is:
    Please Login or Register  to view this content.
    I hope that this makes sense, and that someone can help.

    Many thanks in advance.

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

    Re: Autofill TextBox on each page of Multipage Userform

    Where's the code for hiding/unhiding the pages when the option buttons are clicked?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-10-2011
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    12

    Re: Autofill TextBox on each page of Multipage Userform

    Hi Norie,

    The code for hiding / unhiding each of the pages is all but the last two rows of my code above.

    There is a checkbox on the first page of the multipage form Pages(0) for each of the countries listed in the code. Each of the checkboxes is set to blank. The code I have written is that if the .Value of the CheckBox is False then the Page.Visible is False. That way only the tabs/pages for the countries selected are visible. Is that the wrong way of doing it ?

  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: Autofill TextBox on each page of Multipage Userform

    That's code that runs when the form is activated, not when an option button is clicked.

  5. #5
    Registered User
    Join Date
    02-10-2011
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    12

    Re: Autofill TextBox on each page of Multipage Userform

    Hi Norie,

    Apologies I misunderstood.

    The other bit of code to actually make each of the pages visible, is individual to each of the 11 pages, as the two below for example.

    Please Login or Register  to view this content.
    Regards

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

    Re: Autofill TextBox on each page of Multipage Userform

    One way I can think of tidying things up would be to have a listbox with a list of the countries on the front page instead of multiple option buttons.

    The listbox can be set up to display a check box next to each country.

    When you want to hide/show the countries you would loop through the listbox checking which are selected/not selected.

  7. #7
    Registered User
    Join Date
    02-10-2011
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    12

    Re: Autofill TextBox on each page of Multipage Userform

    Thanks Norie,

    It is a thought, but I don't yet know how to set up a listbox with check boxes next to each item. I will have a go though.

    Meanwhile, back to the main point of my posting. Is there a simpler way of autofilling the two TextBoxes on each of the pages/tabs other than coding to each page individually per the last two lines of my first code above ?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Well the idea of using a listbox was kind of intended to help with that part too.

    How do you have the data set up?

  9. #9
    Registered User
    Join Date
    02-10-2011
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    12

    Re: Autofill TextBox on each page of Multipage Userform

    The two textboxes are user input on the first of my two userforms, which I want to show as an aide memoir on each visible page of the multipage second userform. This is a brand new project so there is no existing data other than various named ranges. I have the countries listed as a named range as part of a page of data with numerous named ranges for different list/combo boxes in case I needed them. Once all set up, and the userforms input/selections have all been completed, the data will be saved in a database. Is this what you mean ?

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

    Re: Autofill TextBox on each page of Multipage Userform

    I thought you had data for each country that you wanted to autofill on each tab.

    Is that not right?

    If you do have a list of the countries in a named range it's kind of handy for populating a listbox.

  11. #11
    Registered User
    Join Date
    02-10-2011
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    12

    Re: Autofill TextBox on each page of Multipage Userform

    No, the data that I want to autofill is text input to two textboxes on the first userform. FYI they are "quotation number" and "study title".

    I have written it the long-winded way into the second userform userform_activate event, as below but wonder if there is a better way of doing it. Could it be that I do not need to have the textboxes on each page called something different ? (would that also apply to ComboBoxes ?)

    Please Login or Register  to view this content.
    Thanks for the smiley tip on populating a listbox with the country named range, but I am using it in a listbox elsewhere, where I only need to select a single country. It was your suggestion of displaying a checkbox next to each item in the list which scared me as I have no idea how to do that.

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

    Re: Autofill TextBox on each page of Multipage Userform

    You can still use the name range to populate another listbox.

    It's pretty straightforward to show check boxes next to each item in a listbox, you only need to change 2 properties.

    Those properties are MultiSelect and ListStyle, which need to be set to fmMultiSelectMulti and fmListStyleOption respectively.

    In code that would look like this.
    Please Login or Register  to view this content.
    Have a look at the attached for an example.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    02-10-2011
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    12

    Re: Autofill TextBox on each page of Multipage Userform

    Thanks Norie,

    Your code above makes sense, so much appreciated. However, with regard to the example worksheet you posted, I am not sure about the coding on that. Does this bit


    Please Login or Register  to view this content.
    mean that it is adding pages based on the number of rows in the countries named range ? I cleared the content of one row in the named range and when I opened the userform it still showed a tab for the row I had cleared but, obviously, with no country name on the tab.

    I have been having problems with opening the worksheet as it kept telling me that it was in use by my laptop so I had to select "notify". However, once opened I had a play with it and it raised a couple of questions. I appreciate it was only an example, but your further guideance would really be appreciated.

    1. If this is adding pages rather than making them visible/invisible, how do I get all the comboboxes, textboxes etc on to the new pages with all the correct ranges, rowsources etc in place?
    2. When selecting the checkboxes in the listboxes, how do I get it to acknowledge the check, leave the selected pages visible and hide the others ?

    Unfortunately the workbook is much too large to post here, but would it help you if I posted a screenshot of the various pages ?

    Many thanks

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

    Re: Autofill TextBox on each page of Multipage Userform

    The only part of the workook I really meant to show was the listbox.

    Adding the pages was just something I was playing about with, and using to save me the bother of manually adding all the pages.

    You can basically ignore it - I imagine you've already created a page for each country with the appropriate textboxes/comboboxes etc.

    As for your question about clearing a value from the country list.

    That doesn't change the named range, so the blank cell is still included.

    Something like that can easily be fixed by using a dynamic named range or not using a named range.

    When do you want to show/hide the pages?

    Would it be as soon as a country is selected/deselected in the listbox?
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    02-10-2011
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    12

    Re: Autofill TextBox on each page of Multipage Userform

    Excellent. Many thanks.

    Yes, you are correct that I ideally want the pages to hide/unhide when the relevant country is selected/deselected. I think I follow the logic of your coding above and, if so, that suits me perfectly.

    I am away tomorrow for a few days on a business trip, but will pick this up again when I get back. If I may, I will leave this thread for now and revert to it again towards the end of the week.

    Once again, many thanks for your generous assistance so far.

+ 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