UserForm Cancel button & combo box entries

  • Hello All,
    This is my first post here so apologies in advance if I'm doing anything sacreligious. I did try searching first, and although I think it must have happened before I couldn't find anything relevant.


    I have a userform with a 'Clear' command button (with the cancel property set to True) so that a user can clear a form half-way through and start again.


    Quote

    Private Sub cmdClear_Click()
    Call UserForm_Initialize
    End Sub


    The procedure it calls is as follows (there are more boxes but I assume it not necessary to show anything more than an example):



    After the Clear button is used, the form is reset and returns to the first combo box but the problem is that the options in all the combo boxes are duplicated, e.g. the first four are shown and then repeated underneath. This recurs every time it is pressed. I'm sure it must be something quite obvious but I can't see it. I copied most of this from another bit of script which works so I am mystified.


    Help would be gratefully received.


    Stephen

  • Re: UserForm Cancel button & combo box entries


    Try this.

    Code
    cboMovetype.Clear


    Also a quick way to reset a form is to unload it then show it.

    Code
    Private Sub cmdClear_Click()
    Unload Me
    UserForm1.Show
    End Sub
  • Re: UserForm Cancel button & combo box entries


    Hi,


    Do you really need to clear and refill the combo or just clear the selected value[vba]Private Sub cmdClear_Click()
    cboMovetype.Value = ""
    cboMovetype.SetFocus
    End Sub[/vba]

  • Re: UserForm Cancel button & combo box entries


    norie,
    Thanks a lot for your prompt response. Works like a dream. I think the second method is preferable as it avoids having to repeat the .clear for each combo box.
    Thanks again.
    Stephen

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!