Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-16-2018, 03:22 PM
jrooney7 jrooney7 is offline Adjust userform layout based on combobox selection Windows 7 64bit Adjust userform layout based on combobox selection Office 2013
Novice
Adjust userform layout based on combobox selection
 
Join Date: Sep 2018
Posts: 23
jrooney7 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 09-16-2018, 06:47 PM
Guessed's Avatar
Guessed Guessed is offline Adjust userform layout based on combobox selection Windows 10 Adjust userform layout based on combobox selection Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 09-16-2018, 06:56 PM
jrooney7 jrooney7 is offline Adjust userform layout based on combobox selection Windows 7 64bit Adjust userform layout based on combobox selection Office 2013
Novice
Adjust userform layout based on combobox selection
 
Join Date: Sep 2018
Posts: 23
jrooney7 is on a distinguished road
Default

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?
Reply With Quote
  #4  
Old 09-16-2018, 07:23 PM
Guessed's Avatar
Guessed Guessed is offline Adjust userform layout based on combobox selection Windows 10 Adjust userform layout based on combobox selection Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
Reply



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
Adjust userform layout based on combobox selection how to populate textbox based on combobox selection in word IvanGeorgiev Word VBA 1 02-21-2013 07:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft