#1
|
|||
|
|||
Adjust userform layout based on combobox selection
Hello all,
I have a userform with multiple textboxes and comboboxes. I have set some to be hidden when the userform is run, and then want them to become visible if certain selections are made in the userform comboboxes. The example below is from the same userform in Excel, and it works there, but it is not working in Word. Any thoughts? Code:
Private Sub SafetiesComboBox_Change() Select Case SafetiesComboBox.Value Case "Other/Multiple" FirearmPreFireUserForm.SafetiesTextBox.Visible = True SafetiesTextBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height SingleActionTP.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 6.5 SAL.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 6.5 SingleActionLowTextBox.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 4.5 SAH.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 6.5 SingleActionHighTextBox.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 4.5 DoubleActionTP.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 24.5 DAL.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 24.5 DoubleActionLowTextBox.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 22.5 DAH.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 24.5 DoubleActionHighTextBox.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 22.5 HybridActionTP.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 43.5 HAL.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 43.5 HybridActionLowTextBox.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 40.5 HAH.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 43.5 HybridActionHighTextBox.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 40.5 Tests.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 4.5 TestAmmo.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 4.5 TestsComboBox.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 16.5 TestAmmoTextBox.Top = SafetiesTextBox.Top + SafetiesTextBox.Height + 16.5 Notes.Top = TestsComboBox.Top + TestsComboBox.Height + 12 NotesTextBox.Top = TestsComboBox.Top + TestsComboBox.Height + 10 Results.Top = NotesTextBox.Top + NotesTextBox.Height + 6.5 ResultsTextBox.Top = NotesTextBox.Top + NotesTextBox.Height + 4.5 FirearmCommandButton1.Top = ResultsTextBox.Top + ResultsTextBox.Height + 22.5 FirearmCommandButton2.Top = ResultsTextBox.Top + ResultsTextBox.Height + 22.5 FirearmPreFireUserForm.ScrollHeight = FirearmCommandButton1.Top + FirearmCommandButton1.Height + 28 Case Else FirearmPreFireUserForm.SafetiesTextBox.Visible = False SingleActionTP.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 6.5 SAL.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 6.5 SingleActionLowTextBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 4.5 SAH.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 6.5 SingleActionHighTextBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 4.5 DoubleActionTP.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 24.5 DAL.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 24.5 DoubleActionLowTextBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 22.5 DAH.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 24.5 DoubleActionHighTextBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 22.5 HybridActionTP.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 43.5 HAL.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 43.5 HybridActionLowTextBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 40.5 HAH.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 43.5 HybridActionHighTextBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 40.5 Tests.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 4.5 TestAmmo.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 4.5 TestsComboBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 16.5 TestAmmoTextBox.Top = SafetiesComboBox.Top + SafetiesComboBox.Height + 16.5 Notes.Top = TestsComboBox.Top + TestsComboBox.Height + 12 NotesTextBox.Top = TestsComboBox.Top + TestsComboBox.Height + 10 Results.Top = NotesTextBox.Top + NotesTextBox.Height + 6.5 ResultsTextBox.Top = NotesTextBox.Top + NotesTextBox.Height + 4.5 FirearmCommandButton1.Top = ResultsTextBox.Top + ResultsTextBox.Height + 22.5 FirearmCommandButton2.Top = ResultsTextBox.Top + ResultsTextBox.Height + 22.5 FirearmPreFireUserForm.ScrollHeight = FirearmCommandButton1.Top + FirearmCommandButton1.Height + 28 End Select End Sub |
#2
|
||||
|
||||
I would recommend you put the context specific content into a MultiPage tab control. Then you can show/hide the tabs to enable/disable chunks. This tends to work more simply than varying the tops/heights of things. It also provides a bit of safety since text boxes out of sight are still part of the tab order (unless also disabled) so the user might tab into one without seeing it on the form.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
That is something to think about, but in the meantime, do you see anything wrong with the code I posted that might give you an idea as to why it's not working?
|
#4
|
||||
|
||||
You haven't given any hints about which bit is not working and I don't have time to try to guess.
Either post a sample document or tell us which line is causing an error. Certainly explicitly naming the userform in a couple of lines but not in others is not great for consistency but without knowing where to look doesn't help us help you.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fill userform, combobox and frame based on data from multiple worksheets | Divinedar | Excel Programming | 8 | 04-26-2018 05:07 PM |
Value of Combobox in other userform | Vibov | Excel Programming | 4 | 11-19-2015 04:12 AM |
Inserting a particular image based on a combobox selection | LeonieD | PowerPoint | 2 | 06-27-2014 05:39 PM |
how to populate textbox based on combobox selection in word | IvanGeorgiev | Word | 1 | 02-21-2013 07:32 PM |
how to populate textbox based on combobox selection in word | IvanGeorgiev | Word VBA | 1 | 02-21-2013 07:28 PM |