Share via

Setting combo box default

Anonymous
2010-10-21T17:21:11+00:00

I want to set the default of a combo box in a user form.  For example if the choices were Red, Blue, Green I would want Red to be the default, ie immediately seen when the user form opens.  I have tried setting the value property but that doesn't work.  Does anyone know a way of doing this.

Thank you for looking at this question

Aehan

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-10-25T16:29:46+00:00

Hi Everyone

It's sorted! I had a UserFormInitialize subroutine for when a new document based on the template was created, and a UserFormActivate subroutine to repopulate the form when a document based on the template was re-opened for editing.  It didn't like both.  I've moved the code for repopulating the form to the OK button code and deleted the UserFormActivate subroutine and the default now works.

Thanks for all your input on this problem, I thought you may like to know how it was finally (cross fingers) fixed.

Aehan

Was this answer helpful?

0 comments No comments

15 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-10-21T18:58:47+00:00

    Thanks, I've moved the code to the initialise event, and it still doesn't work.  For some reason it doesn't seem to see the Value property. :( 

    Any thoughts?

    Thanks for your help.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-10-21T18:17:39+00:00

    Hi,

    I wouldn't do that, put all your code in the initialise event

    Private Sub UserForm_Initialize()

        With ComboBox1

            .Clear

            .Style = fmStyleDropDownCombo

            .AddItem "Red"

            .AddItem "Blue"

            .AddItem "Green"

            .Value = "Red"

        End With

    End Sub


    If this post answers your question, please mark it as the Answer.

    Mike H

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-10-21T18:13:04+00:00

    Hi Mike

    I have a function:

    Function SetType(cmbType)

        With cmbType

            .Clear

            .Style = fmStyleDropDownCombo

            .AddItem "Red"

            .AddItem "Blue"

            .AddItem "Green"

            .Value = "Red"

            .ListIndex = 0

        End With

    End Function

    Then on the userform_intitialise event I have

    Private Sub UserForm_Initialize()

       SetType cmbType

    End Sub

    I tried putting cmbType.value = "Red" as you advised but it's not working.  Have I done something wrong with the function?  Thank you very much for taking the time to look at this.

    Aehan

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-10-21T17:47:35+00:00

    Hi,

    How did you try it, this works for me if you put it in the userform_initialise event

    ComboBox1.Value = "Red"


    If this post answers your question, please mark it as the Answer.

    Mike H

    Was this answer helpful?

    0 comments No comments