+ Reply to Thread
Results 1 to 117 of 117

Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

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

    Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I have a Multi-Page UserForm in Excel 2010. I want there to be a field for the user to specifiy how many additional pages they need to add to the form (each additional page will reference a number of people).

    The UserForm currently has three pages and the user will only need to duplicate page 3. I found the following information online,

    Dynamically Add/Remove a Page:

    Using the Add Method: Syntax: Set m = MultiPage1.Pages.Add(pageName, pageCaption, pageIndex). pageIndex (optional) is an integer which specifies the position for the Page to be inserted, starting from 0 for the first position/Page. pageName sets the Name for the Page, pageCaption sets the Caption. Both are optional to specify.

    Set m = MultiPage1.Pages.Add("Page5", "NewPage", 1) - this code adds a new Page with name Page5 and Caption NewPage, as the second Page (viz. second position in the page order).

    MultiPage1.Pages.Add "Page3"; MultiPage1.Pages(2).Caption = "NewPage" - these 2 codes add a new (third) Page with name Page3 and set its Caption to NewPage.

    MultiPage1.Pages.Add - this code simply adds a new Page.

    To Remove a Page - Syntax: MultiPage1.Pages.Remove (pageIndex). Example: MultiPage1.Pages.Remove (1) - this code removes the second Page.

    So, to test this I created a button and below is what I put into my code, but this hasn't been working. I've been getting a Compile Error: Method or data member not found. The name of my worksheet is 'IntvwWorksheet' and the name of page 3 is 'Candidate1'.

    Please Login or Register  to view this content.
    Can someone help me with this. Since I want the user to be able to say they want to add, for example, 5 more duplications of page 3, or 10 more duplications of page 3, it would be helfpul to know how to specify this as it may not always be Candidate2 or page insertion at 4.

    Currently, I have this as a button, but again, I would like a field where the user can simply specify how many they want added.

    Thank you for your help.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Is anyone able to help me with this part? It's the toughest part and I'm getting stumped with how to proceed.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    If this is in a userform as I assume it is, why are you referencing a worksheet? Shouldn't you be referencing the multipage control?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Because, for each added Page 3, I would also need an Worksheet, I would assume. Unless, when the user presses the print button, I am able to set the code to print one by one, each worksheet for each page added.

    The worksheet has what looks like a form that the UserForm will help the user to input data. Then, the user will print the final result for use as needed.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I'm confused, worksheets have nothing to do with userforms.

    I think you want something like:
    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Kyle, thank you for that. I will give it a try. Will the name change as the number of additions are made? For instance, right now you have Candidate 2, but if the user does this a aga and again, will there be Candidate 3, Candidate 4, etc?

    The reason for the worksheet, is there is currently what looks like a form on the worksheet. There is one worksheet for each person/candidate. If there is a second candidate added to the UserForm, shouldn't there be a second worksheet created as well for the second candidate? Else, where would the first and second, third, fourth, and so on, candidate's information go after the UserForm is completely filled out the data entered onto the worksheet?

    My UserForm is not the customary tabulor format. This content will be placed onto the excel worksheet accordingly. It's designed in such a way to save the user time and make things much simplier for inputing information into a excel spreadsheet they already use.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Isn't 'IntvwWorksheet' the name of the userform that MultiPage1 is on?
    If posting code please use code tags, see here.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    This worked and didn't work at the same time. It added another sheet, but it didn't carry any of the set-up from page 3, Candidate 1 over to Candidate 2. Not only does another page need added, it needs to carry over the userform on page 3 to page 4 and so on so the user can enter the second candidate's information.

    I'm not sure of the correct termonology. All of the labels and value fields from page 3 should duplicate to page 4, page 5, page 6, etc.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Norie, Yes.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    You need code to either copy or recreate the controls on the new tab.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Yes. This is what I need.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    And, to recreate the worksheet at the same time. Previously, I had almost figured that part out as follows:

    Please Login or Register  to view this content.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    That code is copying a sheet, it has nothing to do with the userform.

    Have you considered not using a page for each candidate?

    You could have a combobox listing the candidates and the candidate page could be populated with the data for the selected candidate.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Are you suggesting the combobox be on the UserForm? That would work. As long as,...
    1. If the user needs to go back to another candidate, they can easily do so.
    2. In the end, after everything is completely filled out and each candidate has been added with all of their information, the User will need to be able to print all of the worksheets at once for all candidates.

    How would I go about setting this up? Here is the updated example:

    Multi-Page Trial Run.xlsm

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I honestly didn't think you would go for that idea.

    Did I not suggest something similar way back?

    1 Yes that can be done.

    2 Not a problem - we can use the existing candidate worksheet as a template.

    I could demonstrate the idea if I had some data to work with.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Yes, you did.... hehehe. I'm finally convinced. You must have been laying in wait for me to come around to it, huh!

    I can't provide real data, only fake data. I wonder how much data you need - just candidate and team information? I will assume so….

    Okay, job 123XYZ will use these interviewers:

    IntA: Superman
    IntB: Spiderman
    IntC: Wonderwoman
    Alt1: Bugs Bunny
    Alt2: Elmer Fudd
    Alt3: Wiley E. Coyote
    Host1: Green Giant
    Host2: The Hulk

    They want to interview the following four candidates:

    Candidate 1
    John Smith
    1234 Main Street
    Hometown, USA
    123-456-7890
    [email protected]
    Employee
    Step_Status = Yes
    Nepotism = OK
    Relo needed = No
    Resume Saved = Yes
    Full-time or Eligible = FT-Reg
    Use Same Intvw Team = Yes
    Employee Ext = 5-1234
    Location = China
    Shift = First
    PSID = 123456

    Candidate 2
    Jack TheBeanstock
    5678 Main Street
    Hometown, USA
    098-765-4321
    [email protected]
    Employee
    Step_Status = Yes
    Nepotism = OK
    Relo needed = Yes
    Resume Saved = Yes
    Full-time or Eligible = FT-Temp
    Use Same Intvw Team = Yes
    Employee Ext = 6-7890
    Location = England
    Shift = First
    PSID = 789012

    Candidate 3
    Suzy Q
    9784 Main Street
    Hometown, USA
    456-789-1230
    [email protected]
    External
    Step_Status = Yes
    Nepotism = OK
    Relo needed = No
    Resume Saved = Yes
    Status in Taleo = OK
    Status in PS = OK
    Full-time or Eligible = Eligible
    Status in EDPM = No
    Use Same Intvw Team = No
    For Interview Team instead use:
    IntA: Wiley E. Coyote
    IntB: Spiderman
    IntC: Bugs Bunny
    Alt1: He Man
    Alt2: Elmer Fudd
    Alt3: Porky Pig
    Host1: Green Giant
    Host2: The Hulk

    Candidate 4
    Mary Poppins
    05678 Main Street
    Hometown, USA
    654-987-3210
    [email protected]
    External
    Step_Status = Yes
    Nepotism = OK
    Relo needed = Yes
    Resume Saved = Yes
    Status in Taleo = OK
    Status in PS = OK
    Full-time or Eligible = Eligible
    Status in EDPM = No
    Use Same Intvw Team = No
    For Interview Team instead use:
    IntA: Wiley E. Coyote
    IntB: Spiderman
    IntC: Bugs Bunny
    Alt1: He Man
    Alt2: Elmer Fudd
    Alt3: Porky Pig
    Host1: Green Giant
    Host2: The Hulk

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Thanks for the data, I'll have a proper look at it tomorrow.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Thank you bunches!

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Have you had a chance to look at this? I'm getting so excited that I'm nearing the finishing line for this UserForm! Just that last part and the print button is all that is left!

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Had a look at it earlier but I needed to re-arrange somethings eg columns.

    I've still to look at it and the userform together to see how they relate, eg what data from the worksheet goes where in the userform.

    One thing I need to ask, how should the user pick the candidate?

    I suggested a combobx but what should go in it? Candidate no? Name?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    A Combobox would be fine.... that's when they would click a drop-down arrow and see a list of names, right? Also, the name of the candidate is who they should see.

    Wouldn't it be feasable for them to have two ways to add candidates....
    1) A box where they say I need "10" candidates - so in the intial stages when they know they have 10 candidates they don't have to add them one-by-one
    2) an option to add another candidate - so later if they find they need to add 1 more candidate for a total of 11, they can do that, too.

    Finally, - just to look ahead, a Print button that prints each of the candidates individually. But, there should also be the option to print ALL candidates and another option to print just one or two candidates - just in case they are printing a candidate or two where corrections had been made or had been added.

    I feel like I'm waiting for Christmas. I love this stuff.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Because I've been playing around with the layout - putting the fields into Frames and correcting code, I thought I should post an updated version....

    Multi-Page Trial Run.xlsm

    Thank you again for your help.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    1 How woud they add more than one candidate at a time?

    2 The no of candidates won't be limited - they can add as many as they like, though you can set a limit if needed.

    The printing thing can be done, probably using a separate userform where the user can pick individual, several or all candidates.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    1. Well, I don't know how the drop-down box you have proposed and are working on would add candidates.

    2. I'm told it's probably a good idea to have a cap so the user doesn't add 100 candidates and slow the program down. A cap of 25 would be fine.

    3. what do you mean by a seperate userform? Will that be a hidden userform or coded behind the 'print' button?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    1 The user would click an add button which would clear the form ready for a new entry.

    2 Slow what program down?

    3 Just a small userform that lists all the candidates in a multi select listbox. The user selects the candidates they want to print, it could also have an ALl option to print all the candidates.

    Anyway here's what I've come up with so far.

    There's nothing to add candidates yet, I've spent most of the time renaming controls.
    Attached Files Attached Files

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Yes, that looks great! I see now how the Full Name has a drop down box, and I see the code you used for cboCandidate. so, you must have added the four candidates a different way since there's not an Add candidate button. Oh, I also see there is something under the Initialize, too. Would you be able to add comments to let me know what changes you make and what you do? Since I've even updated the form since I gave you the one you've been working on, later I'll need to combine the two and I don't want to miss something.

    I was told somewhere along the line in my research that having too many pages in a Multi-page UserForm could bog Excel down... but, this isn't adding pages, this is a drop down box - so it may be a different story.

    I like your idea for printing. That will work

    I truly appreciate your help with this!

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Oh, I see how you commented out the done button. How will the program know where to put the content on the underlying Excel Worksheet when it prints? Or, is this still in the testing stage?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    That still in the not even started stage as is any code to add a new candidate.

    The code to add a new candidate should be straightforward.

    The printing code might be a bit more complicated, especially if you have a new form.

    I commented out the code for the Done button because I didn't want to run it but I wanted to keep it for when it came to the printing
    as it could be used as some sort of guide to where the data goes in the form.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Alright. Great. I look forward to the next step!

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I have been so swamped today that I haven't had a chance to touch base with you and see how this process was going. I know you are probably having to look deeper into how everything works. I will just look forward to talking with you on Monday. Does that work for you?

    I appreciate your help!!

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Hi Norie, how is it coming along? I know there is a lot of things to figure out, I just want to touch base with you to know how it's coming along. Do you know how long it will take (not rushing, just looking for an idea so I don't keep bothering you )

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I think I may have figured something out. The letters, D, E, F, G, H, I, etc. are corresponding to the column headers under the tab in the excel worksheet called, CandidateData"

    I can change these letters accordingly so they actually go into the specific cells in what you renamed as the excel worksheet, 'CandidateTemp' as I have listed within the 'ButtonDone_Click()' you had commented out. I believe I would need to still have the ButtonDone, but remove those items pertaining to the candidate's only as they will be addressed down below. Right?

    I want to make sure I am following this correctly.

    Edited to add this question: In order to keep the CandidateData tab in the workbook, perhaps I shouldn't choose to change D to C3, but add both to the code, so it goes to both places?
    Last edited by eemiller1997; 12-04-2012 at 02:11 PM.

  33. #33
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    I don't quite understand what you mean.

    You should leave the data as it is and alter the code for putting data in the form to take those values instead of values from the userform.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Oh, I think I understand what you are saying. So, when a user is done, the candidate's information is collected from "CandidateDate" to the 'CandidateTemp'

    Should ALL information from the UserForm be directed to CandidateData instead of the form?
    Should I recode the If Then statements to go to CandidateData, too, instead of straight to the form from the UserForm?
    After figuring out how to allow the user to add more names from the UserForm, how will the user print each candidate at that point?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    That's what's meant to happen - I just need to work out what goes where.

    None of the data from the userform is directed to the form, it all goes on CandidateData.

    What If Then statements are you referring to?

    For printing there will be a small userform listing all the candidates in a listbox.

    The user can select individual candidates to print or select to print them all.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Okay. Great. There are a few If Then Statements.

    One for Employee, Agency, External.
    Use the same team or not
    Relocation

    Just off the top of my head. I may be adding a few more.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Have a look at the attached.

    As for the If/Then enabling/disabling of buttons have you considered leaving that stuff until
    you've got the basics of the form working?
    Attached Files Attached Files

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Oh, the 'Print Candidates' dialog box. Yay! That's perfect. I would assume when the list becomes longer than the available box, a scroll bar will be revealed?

    Yes, waiting until the basic part of the form is completed will be fine. I'm thinking ahead.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Is the print button supposed to work yet? When I tested it, something flashed quickly, as if it were going through the act of printing 4 times, but nothing came out of my printer, so I am assuming it's not going to work yet. If that's the case, what's missing?

    This is so exciting. I love this!

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Here is an attachment that shows all of the information inputed.

    Multi-Page Trial Run.xlsm

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Ok, I have updated everything to the degree I know how, including the print button and the combo box. I have added worksheets to store the data and updated the fields in the cboCandidate.ListIndex.

    There were a couple of things there I need to figure our regarding the If Then Statements, but that will be figured out later, so I commented them out.

    I used the same list of candidate you had inputed and completed the information. So, there are four candidates. Though, when I test the combobox in the UserForm, it doesn't show a list of candidates. Where have I gone wrong? (Please see attached)

    When I click the 'print' button on the UserForm, I get a 'Compile error: Variable not defined' and it then highlights the sectoin below. Where did I go wrong?

    Multi-Page Trial Run.xlsm

    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I won't have time to look at this tonight but can I just clarify that you do not need the yes/no thing to decide whether or not the interview can be altered.

    When a new candidate is created the interview team for them will be the standard one for the job.

    If the user wants to change any of the team they can just do it, there's nothing stopping them.

    Once they have finished entering all the data for a candidate they'll click a save button will will take all the data fromt he candidate tab and
    put it on the CandidateData sheet.

    The reason for the error is because it's a listbox called lstCandidates not a combobox called cboCandidates.

    cboCandidates in on the Candidate Information tab of the main form.

    The reason the combobox doesn't get populated is because there doesn't appear to be any code to populate it.

    Pretty sure there was in the file I attached.

    What else did you change?

    PS Thanks for the data, that is a really helpful as it gives me something 'real' to work with.

    PS Almost forgot, how did you input data? Directly to the worksheet?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Quote Originally Posted by Norie View Post
    The reason the combobox doesn't get populated is because there doesn't appear to be any code to populate it.
    Is this not the code to populate it?

    Please Login or Register  to view this content.
    The reason for the error is because it's a listbox called lstCandidates not a combobox called cboCandidates.

    cboCandidates in on the Candidate Information tab of the main form.
    I'm confused because that's how you had it...., in fact, I actualy copied the code you had and pasted it into my form for the frmPrintCand...

    Please Login or Register  to view this content.
    I changed the names of the fields to have an underscore after 'Cand' and removed the '1' like you had (I didn't update them in the code for the If Then Statements). I created two worksheets- one to store the content for Job Interview and Team Information, it's called 'JobIntvwData' and another for the Candidate Data called, 'CandidateData'.

    I put a column for each part of the UserForm into those worksheets and then corresponded their column number in the code area I shared above.

    I think that was all the changes.

    I inputed the data directly into the worksheet.

    Of course, the If Then Statements are not yet addressed, but before I had made those above changes andafter you had recieved a copy of this Userform, I had made some form changes - such as changing Relocation to optionbuttons instead of checkboxes. I've coded all of my If Then Statements as needed before these changes.

    I don't understand your note about changing the interview team. You will have to show me and help me understand. Because initially, there was no yes/no option and the code,

    Please Login or Register  to view this content.
    caused it that when I changed Cand1_IntA's value to something other than IntA it just simply reverted back to IntA, because that's how it is coded. Changing it to a yes/ no option box allowed me to code the above for the yes and the no allows for changes.

    Thanks for your help. You said you wouldn't be able to look at it tonight. Do you know when you'll look at it? I don't want to bother you if you haven't had a chance to look yet.
    Last edited by eemiller1997; 12-05-2012 at 05:09 PM.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Oh, I forgot. I also added a Notes to Tab 2. I split the notes sectoin on the Excel form so the top sectoin is for the Job Information and the bottom section is for the candidate. Not sure if you were concerned about that kind of change.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I think we might be on the wrong workbook.

    The last file I attached was meant to replace the original workbook.

    I'll have a proper look at the last file you attached tomorrow, especially the data which as I said wil be really useful.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Thank you

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Hi Norie, Have you had a chance to figure out where I went wrong? I should have just used the one you had made and customized it to my needs. Instead, I was trying to make sure I understood everything by putting it into the form I had customized to our needs. Yesterday, I was going to try to see if I could adjust yours, but I got stuck on the fact that for some reason there is something funky happening with the actual excel worksheet form. So, I'm still stuck waiting to know what I had done wrong with mine. I'm sure it's something simple. Please help!
    Last edited by eemiller1997; 12-07-2012 at 11:32 AM.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Norie, I tried simply updated the "Print Button UserForm: version you had sent me, but it's also coming up with an error. So, somewhere along the line I'm doing something wrong. I didn't even make it very far. I simply updated the CandidateData worksheet with all of the fields we needed and then made sure the code for the cbo had the correct columns associated with the correct value field. Perhaps if each piece of the code were explained to me I could find the problem. I don't know. I just need to get it figured out.

    Thank you for your help!

  49. #49
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    What do you need explained?

    Also, why are you changing things?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    The attachment from Wednesday is still not working. I can't seem to figure it out and I've been scouring the internet for direction. I thought I would look at the example you provided and copy and paste it into my Userform and update field names and placements, etc. But, it didn't work. You didn't have time to look at it that night to figure out where I had gone wrong. So, while I waited I was trying to use the version you had provided to update it to my needs, but my changes caused it not to work, too. So, I'm back to trying to figure out where I had gone wrong in the recreation of your version to mine. In the version you made, it works great (minus the add button not yet coded), but there were missing fields that I had provided you, so I added them to the worksheet, "CandidateData" in the order I wanted them in. Then, in the code, I added those fields and their associated column headings. I need to be able to make adjustments to it and understand how it works for the possibility of future customizations. But, after that was all done I would go to the UserForm and the ComboBox for Candidate Name didn't have any list of candidates in it. So, something I had done had messed with whatever code told the combobox to take from that list of candidates in the CandidateData worksheet. And, then, the print button no longer worked either. Did you have a chance to look at the document I had attached Wednesday to see where I had gone wrong?

    As far as the questions, What causes the combobox to take from the names on that worksheet? What code causes the data inputed into the userform to go to that worksheet? What causes the combobox to connect to the rest of the selection on the combobox, as my research all I can find it how to add options to the combox independently of the rest of the form and this is set up as one - the combobox selection is tied to all of the rest of the inputed data on the candidate information. I'm not sure where in the code it tells it to do that.

    Thank you for your help!

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Where should I start. First, I would think to know why it's not working... both the CBO and the Print button. Then, I throught that process I will probably be able to get answered those above questions. Next, would be the add new candidate. Finally, the If Then Statements. Then, that should be about it. So close to finishing this.... I'm anxious to finalize it.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    What causes the combobox to take from the names on that worksheet?

    Look at the code for the main userform's Initialize event.

    What code causes the data inputed into the userform to go to that worksheet?

    No code currently does that, that's what an Add button would hopefully do, if we ever get there.

    What causes the combobox to connect to the rest of the selection on the combobox?

    Not sure what you mean by 'rest of selection on the combobox.

    All that's in the combobox is what you see, the candidate names.

    Are you wondering how the rest of the form is populated when a candidate is selected?
    Last edited by Norie; 12-08-2012 at 12:31 PM.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Quote Originally Posted by Norie View Post
    Are wondering how the rest of the form is populated when a candidate is selected?
    Yes, please

    Have you had a chance to look at the above attachment to see where I went wrong?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    When you select a candidate from the combobox this code is triggered:
    Please Login or Register  to view this content.
    This line puts the ListIndex of the combobox into the variable idx.
    Please Login or Register  to view this content.
    The ListIndex of the combobox indicates which candidate was selected in the combobox.

    If it's the first candidate listed the ListIndex will be 0, if it's the 2nd the ListIndex is 1 and so on.

    If no candidate is selected the ListIndex is -1.

    We check for that here.
    Please Login or Register  to view this content.
    If no candidate is selected then the following code is skipped.

    However if a candidate is selected we can find the row that the selected candidate's data is on by adding 2.

    If we've selected the first candidate in the list the ListIndex will be 0, if you look on the sheet the first candidate's data is on row 2, so to
    get the row we add 2 to the ListIndex

    If we've selected the second candidate in the list the ListIndex will be 1, if you look on the sheet the second candidate's data is on row 3, so to
    get the row we add 2 to the ListIndex.

    And so on.

    Once we have the row the data is on we can populate the userform.

    The variable idx is used just to simplify things, without it the code to populate the userform would look like this.
    Please Login or Register  to view this content.
    Hope some of that made some sort of sense.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Yes, that makes sense. Thank you for that. I'm going to go through this with a fine tooth comb. Any idea, though, why mine isn't working?

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

    That's mainly because I have no idea what workbook you are working with.

    I know it's a pain but could you upload the workbook you ate currently using?

    Also can you give it, and any subsequent workbooks you upload, some kind of name that reflects the 'version' it is?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    It is no pain at all because I appreciate your help. Here is the current version and I've renamed it so we know it's the combobox and the print button with the troubles.


    ComboBoxPrintBox_Troubles.xlsm

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I explained what the problems were back in post #42.

    To fix them this code needs to go in the IntvwWorksheet module,
    Please Login or Register  to view this content.
    and in the frmPrintCand module change the Initialize code to this.
    Please Login or Register  to view this content.
    Last edited by Norie; 12-08-2012 at 07:06 PM.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Alright. I see what you were saying. I had cbo where lst should have been in the frmPrintCand module. I've changed that as well as added the initialize as you have above for the IntvwWorksheet module, but there is still something wrong and for both forms now. I'm attached v2 for your review.

    ComboBoxPrintBox_TroublesV2.xlsm

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Why have you put the code for the print form in the main form's module?

    Also, it's lstCandidates not lstCandidate for the print form.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Okay, I'm confused. I've fixed the typo under the frmPrintCand module, however did you say to put that other code in the IntvwWorksheet module? Isn't that what I did? Where did I misunderstand?

    ComboBoxPrintBox_TroublesV3.xlsm

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    This is what I said.

    Quote Originally Posted by Norie View Post
    I explained what the problems were back in post #42.

    To fix them this code needs to go in the IntvwWorksheet module,
    Please Login or Register  to view this content.
    Last edited by Norie; 12-08-2012 at 07:27 PM.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I know that's what you said, what is confusing me is how is that different from what I did?

    IntvwWorksheet.jpg

  64. #64
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    You didn't put the right code in the main form's module.

    You put the same code as you had put in the print form module.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Ugh! I can't believe I did that. I blame it on my cold. I've fixed that, but I'm still getting an error when I simply test to see if the form is working correctly. Any ideas?

    ComboBoxPrintBox_TroublesV4.xlsm

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    It's cboCandidate not cboCandidates.

    PS Don't you just copy and paste?
    Last edited by Norie; 12-08-2012 at 09:47 PM.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Yay! It's finally working. My brain is just not working 100% today. Thank you for that!

    What will need to change with the If Then Statements with the set up like this? Because, instead of using a 'done' button, the cboCandidate.List is coded to tell excel in what column of CandidateData to place the answers. How do I handle the If Then Statements, then?

    For example, with relocation the code for an answer 'yes' is as follows:

    Please Login or Register  to view this content.
    and if the answer is 'no', the code is as follows:

    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    There is no code to place data on 'CandidateData'.

    The code for getting the data from 'CandidateData' is all there is right now.

    When it comes to creating code to place the data on 'CandidateData' these 2 subs wouldn't be used.

    The If/Then code would be in with the rest of the code for placing data.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    So, all of the If/Then's will still work just as is? I guess I had understood the code for the CboCandidate sent the data to the worksheet CandidateData and then the Print userform pulled the information from the worksheet CandidateData into the Form. That must not be correct, then? Because I have all of the If Then's coded to place certain answers within particular cells within the form.

    If the If/Then's all work as is, then there are two more things to complete this project:
    1. How a user adds a candidate.
    2. Making the Print button actually print.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    No the If/Then code should basically be removed from where it is as they write directly to CandidateTemp.

    Where it belongs, and probably in a different form, is in the code that transfers the candidate data to a form.

    1 Yes that needs to be done.

    2 The print Selected button does work, the print All button just needs this line uncommented.
    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I've added a some basic code to add new candidates and update existing candidates.
    Attached Files Attached Files

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I have uncommented that line and tested the print button. I received a Run-Time error '9' Subscript out of range. Then, it pointed to this line:

    Please Login or Register  to view this content.
    Where it belongs, and probably in a different form, is in the code that transfers the candidate data to a form.
    Isn't the code that transfers the candidate data to a form currently stored under the worksheet called 'CandidateDate' see V5 attached. Previously, I had updated that worksheet with all of the columns necessary, to this point, for all data to be collected from the user for the Candidate. I renamed the other worksheet that collects the data for the job and interview information to 'JobItvwData'

    So, under 'CandidateData' there is a column for 'Relo needed' and 'Travel authorization', perhaps there is also necessary for a column for the answers ***** as outlined in the above code for the If Then Statements for relocation or travel necessary?

    Can you walk me through one of these? To place it exactly where it needs to go and how to set it up so I can duplicate that method for the rest of the If Then Statements?

    ComboBoxPrintBox_TroublesV5.xlsm

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Just to clarify, I don't want the user to have to go to a different form altogether to input these if then answers.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    The error is because you've changed the name of from CandidateTemp to CandidateForm.

    There is no code stored under any worksheet.

    There is not need for columns for the ***** answers.

    They are based on the values of certain controls.

    If we write those values to the worksheet then we can deal with it when we are actually filling out the form with candidate data.

    Can you please look at the workbook I just posted?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Thank you for pointing out you had uploaded something. I've looked at what you've uploaded. Testing the form, the user selects 'NewCandidate'? Is that how? When I tried that, it gave the new candidate information already entered into the UserForm. Also, when I tried to change the name for New Candidate and information, it didn't add my new candidate to the list. When I tried to click, Add/Update button, it didn't provide anything, either.

    With regard to the columns for the ***** answers, I am confused by this, but will wait to see this in action to see what you mean. As long as the user can say Candidate Angie Johnson needs relocation and Candidate John Doe doesn't and the proper answers are placed in the worksheet along with the corresponding ***** in the correct cells for the appropriate candidate, I'm happy

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Yay, the print now works.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    NewCandidate was a new candidate that I added when testing (lightly).

    I was thinkin of a new button next to the canidate combo which would clear most fields but fill in 'default' values where necessary.

    The code in the Add/Update button checks if the name is one on the list ie an existing candidate or it's a new one.

    It then adjusts the row to put the data in as required.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Oh, I understand now, one adds a new candidate and uses the 'add/update' button to add him/her to the list. That makes sense. I would prefer there be no 'default' values, just simply an empty form for the user to input data. Since the form is a measure to insure all information has been researched and entered, if the user comes across content that defaulted, gets interrupted for any reason and returns to find that field already inputted, they may think they had already researched that piece and mistakenly move on.

    I need some help understanding something. When I used the print button it printed the four forms for the four test candidates already there. The information from the UserForm is not in the correct place within the printed form. For instance, 'No Travel Necessary' is in the cell for something else. This is the case for most of the form. Also, none of the Job Information and Interview Information is on the form at all.

    looking at the code, it appears this is the code telling the system where to place the Interview Information and Team Information:

    Please Login or Register  to view this content.
    I understand that as it's saying the field names within the UserForm named 'IntvwWorksheet' go into those fields on wsForm (I don't know what wsForm means, but I'm assuming it's the worksheet form?). But, why did none of the data go into those cells?


    And, it appears this is the code telling the system where to place the candidate information:

    Please Login or Register  to view this content.
    This is what looses me as I don't know how to identify what is what. I do know it is taking information from CandidateDate worksheet, I just don't know how it knows, for instance, J19 is Cand1_IntA. It must have something to do with the number '20' as it's the only difference between each line of code, but what is that number refering to?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Well, it seems I've made a mess of things again. First, to understand the above question. Second, where to put my If Then Statements and Third, how to properly add/update candidates.

    I've tried researching online and to look into the books I have on VBA to understand the above question, however what I run into is a problem where everyone explains the difference between a list and a combobox. Got it. Or, how to create values for the combobox to have. Got it. But, nothing explains how to connect the combobox to multiple fields on the same page of a userform, like Page 3 does. Or, how to code what is coded above. We enter an answer into a field on the UserForm and it's stored on a worksheet in the Excel file. Then, later placed into the form on the CandidateForm when user 'prints'. But, I can't find anything that explains this process and the underlying code. I'm lost and don't know how to fix things.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Norie, progress is being made! With some help, I learned in the following code,

    Please Login or Register  to view this content.
    The 1 is referring to an offset of the first column of the CandidateDate worksheet, every column having it's own number offsetting from the first column. With that in mind, I was able to put together the rest of the code and test print it. The results - everything is in it's correct placement that came from the worksheet named CandidateData. And, I've been able to successfully add candidates!!!

    There are still two things to address and then I am done!

    1) How to get the data from the worksheet called JobIntvwData onto each worksheet? I see how they are noted above within the frmPrintCand, however, they don't transfer like the CandidateData does. Not sure why not.

    2) How to fit in the IF THEN statements. They are very important. They are currently not working within the UserForm, either.

    Can you help me with both of those question?

    Here is the updated version of the project:

    ComboBoxPrintBox_TroublesV6.xlsm

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    1 You know where the data from that sheet should go, so it shouldn't be hard to work out.

    Please Login or Register  to view this content.
    2 The If Then's shouldn't be in the userform code, they belong in the code for filling out the form.

    Here's an example which goes in the sub FillForm.
    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Yay, part one of your answre above worked splendidly. I'm so excited. So close to finishing!!

    Quote Originally Posted by Norie View Post
    2 The If Then's shouldn't be in the userform code, they belong in the code for filling out the form.

    Here's an example which goes in the sub FillForm.
    Please Login or Register  to view this content.
    Where should the THEN statement be? I don't see the THEN in the above code. Just before the "*****"?

    Is there a shortcut to code multiple places with ***** if the answer is Employee? The original If Then Statement was as follows:

    Please Login or Register  to view this content.
    Notice also that the fields within the Userform also became disabled based on the If Then statement. Where will that be done?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    oops, one more question in addition to the above. As I was further testing the userform, starting with Tab 1 and entering information, how does that information go to the JobIntvwData worksheet? Since, the print button is coded to pull from that how does the user get the information there?

    Another issue is when I entered a name into the candidate combobox that was similar to a name already there, for instance, Joseph ______ the previous Joseph's information came up. How do we prevent that from happening?

  84. #84
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Did you pick the right Joseph?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I didn't want to pick a Joseph. I was pretending to type in a new Joseph and it auto-populated with the already inputed Joseph before I could get to typing in a last name. After I did type in a last name different from what was there, the auto-population remained. What do you recommend? Then, I couldn't undo that action, so perhaps a clear button would be a good idea. What do you think? If so, how would a clear button be coded?

    I'm still completely stumped by the If Then Statements for this new set up. If they are not to be in the new format, or if they are going to be in the new format, how do I address everything and where?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    The Ifs that do things on the userform, eg enable/disable controls, should stay in the userform code.

    The Ifs in the userform code that put values on the candidate form should be moved to the code that populates the candidate form.

    Change the MatchEntry property of the combobox to frmMatchEntryNone.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Alright, that makes sense. I have not yet removed the If Then statements from the UserForm and I noticed while using the userform, the If Then statements are not happening on the userform right now, but perhaps removing some of the other stuff will enable that. Let me give that a try and I will get back to you.

    I will make that change to the property. Thank you !

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Check the names of the controls on the form.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    What do you mean? To control which part?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I've just taken another look at your last attachment.

    Where are you storing the data for the interview team?

    I don't mean the interview team for each candidate, I mean the 'default' interview team for the job.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Quote Originally Posted by eemiller1997 View Post
    What do you mean? To control which part?
    I mean check the names of the controls throughout, if you don't you'll get errors.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Since I had planned to use the yes/no option box for using the same interview team as a method to fill or leave blank for the user to fill in the interview team on the candidate page, I had believed it would simply be stored with the candidate information on the CandidateData worksheet. This is because if the user says 'yes' the same interview team will be used, then the names from tab 2 of the userform will autofill into that area of tab 3 of the candidate information. Otherwise, it will be left blank for them to make changes as necessary.
    Last edited by eemiller1997; 12-11-2012 at 09:24 AM.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    How can I get the information from tab 2 and tab 3 to go to the JobIntvwData worksheet and then pulled from there when 'printed'?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Doesn't the interview team data 'belong' to the job?

    If it doesn't which candidate's job interview team should be used?

    Also, wouldn't it make sense to have the interview team filled in for each candidate?

    That can be done when the new candidate button is pressed.

    If any changes need to be made to the interview team for a particular candidate then they can be done on the form and will be saved
    to the CandidateData worksheet.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Yes, the interview team belongs to the job, but quite frequently we are told that different interviewers will cover different candidates. So, I added a section within the candidate's area on Tab 3 asking if the same team would be used. If yes, then the section autfills with the team already placed on Tab 2. If not, then it's left blank for the user to enter the names of the team that will be used.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Why not just automatically fill in the interview team for the job.

    If you don't then it's going to look like some candidates aren't going to be interviewed by anyone.

    There's absolutely nothing stopping the user making changes to the team, and those changes will be saved.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    That's fine and would save time and was my initial plan - however, I had found that if it's coded to duplicate from tab 2, then it wouldn't allow the user to overwrite it. That was the topic I had asked about during another post in this forum. But, if you say it will work, I will trust you. Just let me know how to set it up that way.

    I figured out how to code the information under the add/update tab so the job information and interivew/team information go onto the form at the push of the add/update button. Now, I just need to code it so it goes to the JobIntvwData worksheet instead. I think I can do that myself. What I need to know is how to keep the information from disappearing from the userform after the user x's out of it?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    That is totally wrong.

    The code that did that should have been dumped long ago, I know I don't have it in the workbook I'm working on.

    The interview team would be taken from the worksheet with the job data.

    I was just about to write that code but was stopped in my tracks when I realised the interview team data wasn't there.

    Why are you putting the data straight from the userform on to the candidate form?

    That's really not a good idea.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Ok, Let me attach my updated version- V7, please.

    ComboBoxPrintBox_TroublesV7.xlsm

    You tell me how to do it correctly, and that's how we'll do it. Just so long as if the team isn't the same, the user will see the team on the Candidate Page so they can make the appropriate changes.

    I did create a worksheet called JobIntvwData where I want the Job and Interview information to be stored.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Oops, I forgot to clarify, I did code it to go onto the form, but that was just to see if it was even going to work. I do want the info to go to the JobIntvwData worksheet for storage.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I realized in order to have the If Then Statements place the answers into CandidateData worksheet, then I needed to put the If Then Statements under the 'Private Sub AddUpdateCand_CommandButton_Click()' with everything else.

    Is this the correct way to convert this If Then Statement?


    This....
    Please Login or Register  to view this content.
    to...
    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I won't be able to have a proper look at your latest attachment until tomorrow.

    As for the if, that's not correct - what I was using in the previous code was an immediate IIf.

    It's syntax is something like this.
    Please Login or Register  to view this content.
    It can only be used to return one value, and is not equivalent to If Then.

    PS Have you added more columns (AF, AG) to the CandidateData sheet?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I did add those two columns for those two answers. I just added them to the end so I didn't have to redo everything else right now.

    I had thought the IIf was a typo.

    If an answer of TRUE is given, it's okay to have three different ifs resulting from the same value? Such as...

    Please Login or Register  to view this content.
    I will look for your help tomorrow on what you were going to do with the attachment.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Hi Norie, Did you have a chance to look at that last night? Did I get that If Then Statement correct in post #103? Thank you!

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    No I've not had a chance to have a proper look.

    No that code is wrong.

    You should use what you originally had, but obviously adjust the ranges.
    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Oh, Ok. Will do. Thanks. I will proceed with working on this. After you have a look at the attachment, please let me know what changes you make so I can transfer them to my working document

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Hmmm, I have added my If Then Statements to the "Add/Update" button and I am getting a "Compile Error: Expected End With" and then it hightlights the 'Private Sub AddUpdateCand_CommandButton_Click()'

    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    That code compiles OK.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Hmmm, then maybe it has to do with where I put it. Here's the code in it's entirety:

    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Count the Withs and End Withs.

    By the way, I don't think that the code to add the job data should be part of the code to add a candidate.

    The job data doesn't change per candidate, it's always the same.

    What you really need is a button on one of the pages where you enter the job data.

    That button will save the data to the relevant worksheet.

    Actually, that brings something up.

    Are you going to be using this for more than one job?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I counted the With's and that worked. And, my If Then Statements are working. Yay!

    The reason I added the code to add the job data when the candidate's are updated was because I didn't see another way to have that information added to JobIntvwData without having yet another button for the user to press. So, I figured when a user enters the job data and then a candidate it would update. Though, I admit that's not the best way. I probably should just create a seperate button on Tab 1 and 2 for that information to update. But, I won't want the UserForm to close. Anyway to code it so the Userform doesn't close upon clicking the button?

    No, I will NOT be using this for more than one job at a time.

    How is the other parts coming along? I know my concern was when the user adds a candidate with a similar name to a previously entered candidate, it automatically populates the rest of Tab 2 with that other candidate's data without reverting to a clear form when the user continues to add a name different from that similar name. So, if there is a Joseph Taylor already in the list and I type Joseph Smith, the moment I start typing Joseph, the data for Joseph Taylor comes up and it doesn't go away as I continue to type the last name of Smith.

    Also, when a user is entering a new candidate to the list, they will want a completley cleared form always. I think there should be a button for 'clear' so the user can do this at any time they need to. Don't you?

    Thank you for your help!! Almost finished

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Oh, and we were still working on the INterview Team thing. Where we want the candidate to be able to make changes as needed on the Candidate page, but the interview team on Tab 2 be the primary unless those changes are made.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Well, I have been testing the userform and such and making necessary corrections. Now, just suddently, after having opened the UserForm by clicking the button on the excel worksheet before with no problems, it wants to give me an error. For some reason it doesn't like the following:

    Please Login or Register  to view this content.
    The funny thing is I was going to ask about this later as the form doesn't even open upon opening the excel worksheet anyway. But, it wasn't a priority. Now it has become one since it won't allow me to open my form without the following error: Runt-Timer Error '381': Could not set the List property. Invalid property array index.

    What happened?

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    There's an error somwhere in the userform code, probably in the Initialize event.

    Goto Tools>Options and on the General tab pick either Break on All Errors or Break in Class Modules.

    Once you've done that click the button.

    You'll still get an error but this time it should highlight the problem line and allow you to Debug.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    Ok. I choose All Errors and it took me to the following code - pointing to the cboCandidate.list..... row.

    Please Login or Register  to view this content.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I'm fairly certain I didn't do anything while making my updates, but maybe I did... but, I don't think so.

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

    Re: Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm

    I hate to keep bothering you. We are just so close to being finished. I can feel it and I'm so excited to get this working. In addition to this new problem, have you had a chance to look at the attachment previously provided to determine the problem with entering names that are similar, how to prevent the form from closing when the user clicks 'Add/Update', and how to set up the interview team correctly?

    When I create the button to enter the Job Information and Interview and Team Informatoin onto the spreadsheet where it will be stored, should I create a button for both tab 1 and tab 2, or just on one? I'm not sure the best way to handle.

+ 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