+ Reply to Thread
Results 1 to 8 of 8

Issue ComboBox change event

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Issue ComboBox change event

    Hi -

    So attached is the workbook I'm using to develop a User Form that displays different results based on a selection from a Combobox. Though I have not completed all of the cases in my 'Select Case' procedure, the code I have does seem to work as intended when I make a single selection from the Combobox. However, when I make another selection from the ComboBox, the codes doesn't seem to fire. Give it a try by running the user form and choosing any of the first three selections (i.e., GCBlack18, GCBlackF9 or GCBlackB9) and I think you will see what I mean.

    This is what I need to have happen:

    The user wants to view the details of a particular course. As an example, let say he selects GCBlack18 from the combobox. Result: the yardage values, the par values and the handicap values appear. But then lets assume the user decides he just wants to see the the details associated with the front nine. Ahhh, here something changes; while the yardage and par values remain the same, the handicap values change. Likewise, if the user then opts to view the details of the back nine only, again yardage and par values remain the same but the handicap values change. Because I have five different tee boxes with different yardages, I am creating the Select Case statements. So far in the attached workbook I have only finished the Case statements for the Black tees (i.e., case GCBlack18, GCBlackF9 and GCBlackB9). I need to make this form diplay whatever results the user desires by simply making new selections from the dropdown list in the combobox.

    Thanks,

    Grilleman
    Attached Files Attached Files
    Last edited by Grilleman; 10-24-2019 at 05:08 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Re: Issue ComboBox change event

    Your code is badly indented so it's awkward to read. With that in mind I've given it a very light read over only.

    However, what strikes me as obvious is you hide the 'irrelevant' controls dependent on the selection made in 'comboboxCourseSelection' but you do not unhide them when a selection is made that would dictate otherwise.

    For example, in the below you can see how one selection hides the irrelevant and shows the relevant and the opposite selection does it the other way round.
    Private Sub ComboBox1_Change()
        Select Case ComboBox1
            Case 1
                TextBox1.Visible = True
                TextBox2.Visible = False
            Case 2
                TextBox1.Visible = False
                TextBox2.Visible = True
        End Select
    End Sub
    Does that help you at all?

    Beth.

  3. #3
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Re: Issue ComboBox change event

    Hmmm. Yes. Thanks.

  4. #4
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Re: Issue ComboBox change event

    If you need more help than that you'll need to provide a lot more information about what should and shouldn't happen on your form with each possible combobox selection.

    Beth.

  5. #5
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Re: Issue ComboBox change event

    Thanks Beth for the input. It seesmto me that Ijust need a way to 'reset the form' before each new ComboBox change event.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Issue ComboBox change event

    Option Explicit
    Private Sub UserForm_Initialize()
        Dim COURSEDATA As Worksheet
        Set COURSEDATA = Worksheets("CourseData")
        Me.comboboxCourseSelection.List = COURSEDATA.Range("CourseSelection").Value
    End Sub
    
    Private Sub comboboxCourseSelection_Change()
        Dim COURSEDATA          As Worksheet
        Dim CourseSelection     As String
        Dim GCBlack18           As String
        Dim GCBlackF9           As String
        Dim GCBlackB9           As String
        Dim GCBronze18          As String
        Dim GCBronzeF9          As String
        Dim GCBronzeB9          As String
        Dim GCGold18            As String
        Dim GCGoldF9            As String
        Dim GCGoldB9            As String
        Dim GCGreen18           As String
        Dim GCGreenF9           As String
        Dim GCGreenB9           As String
        Dim GCSilver18          As String
        Dim GCSilverF9          As String
        Dim GCSilverB9          As String
        Dim ColPtr              As Long
        Dim Suffix              As Variant
        Dim CourseSelectionRow  As Long
        Const YDS = 4           'YARDAGE
        Const PAR = 25          'PAR
        Const MH18H = 46        'MEN'S HANDICAPS - 18 HOLES
        Const MHFR9 = 64        'MEN'S HANDICAPS - FRONT 9
        Const MNBK9 = 73        'MEN'S HANDICAPS - BACK 9
        Const WH18H = 82        'WOMEN'S HANDICAPS - 18 HOLES
        Const WHFR9 = 99        'WOMEN'S HANDICAPS - FRONT 9
        Const WHBK9 = 8         'WOMEN'S HANDICAPS - BACK 9
    
        Set COURSEDATA = Worksheets("CourseData")
        CourseSelectionRow = frmEditExistingCourse.comboboxCourseSelection.ListIndex + 3
        [A1] = CourseSelectionRow
        CourseSelection = frmEditExistingCourse.comboboxCourseSelection.Value
    
        ColPtr = 0
        For Each Suffix In Array(1, 2, 3, 4, 5, 6, 7, 8, 9, "OUT", 10, 11, 12, 13, 14, 15, 16, 17, 18, "IN", "TOTAL")
            ColPtr = ColPtr + 1
            Me.Controls("TextBoxYardage" & Suffix).Value = COURSEDATA.Cells(CourseSelectionRow, ColPtr + YDS).Value
            Me.Controls("TextBoxPar" & Suffix).Value = COURSEDATA.Cells(CourseSelectionRow, ColPtr + PAR).Value
            
            If ColPtr <= 18 Then
                Me.Controls("TextBoxHandicap" & ColPtr).Value = COURSEDATA.Cells(CourseSelectionRow, ColPtr + MH18H).Value
            End If
        Next Suffix
    End Sub
    Attached Files Attached Files
    Ben Van Johnson

  7. #7
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Re: Issue ComboBox change event

    Ben -

    Thanks for this. It's a bit advanced for me so I'll need to study. Meanwhile, I was able to accomplish my goals using 'Select Case' statements. With Beth's (BanginMyHeadOnMyDesk) help I realized I could simple turn all labels and controls on and set all captions to there default values 'at the Case level' and then selectively turn them off 'at the case level' as needed.

    Still, thank you for the effort and what has become my newest learning assignment.

    Best,

    Grilleman

  8. #8
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,309

    Re: Issue ComboBox change event

    Hi.
    I am a little late with this one.
    As the data listing was somewhat changed in your present example.
    There is no need for complicated searches, you simply use the combobox listindex.
    As per the attached, keep things simple and easy to read.
    torachan.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] ComboBox Change Event error
    By natefarm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2018, 06:04 PM
  2. Combobox change event
    By buhwheet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2015, 10:39 AM
  3. ComboBox Change Event Issue
    By Ezzard in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-09-2015, 02:22 PM
  4. Change event for comboBox
    By cmpcwil2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2006, 10:01 AM
  5. [SOLVED] Combobox change event issue
    By Excelerate-nl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2006, 08:10 AM
  6. Combobox change event only by UI
    By Excelerate-nl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-02-2006, 11:10 AM
  7. [SOLVED] MsgBox in Enter event causes combobox not to run Change event
    By Richard in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2006, 10:55 AM

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