Reset / Clear ComboBox

  • I have a userform with several combo boxes on it. I also have three command buttons, 'OK', 'Reset' and 'Cancel'. I want to code the 'Reset' command button to reset the values of the combo boxes to empty or "". I have attempted to do this simply by using the following code.


    Code
    Private Sub cmdReset_Click()
       cmbWaterTemp.Value = ""
       cmbTypeFastIce.Value = ""
       cmbIceDrift.Value = ""
       cmbTrendBehavior.Value = ""
    End Sub


    When I click on the 'Reset' command button I get the following error.


    "Run-time error '94':
    Invalid use of Null"


    When I use the debug tool the error pointed to is a different sub.


    Code
    Private Sub cmbWaterTemp_Change()
       txtTemp1Encoded.Text = Left(cmbWaterTemp.value, 1)
       txtTemp2Encoded.Text = Right(cmbWaterTemp.Value, 1)
    End Sub


    I am not exactly sure why the error points to this sub. I know there must be a simple way to accomplish this. I am including a workbook that is similar though not exactly the same due to file constraints. What I want to happen is when the 'Reset' button is clicked is to clear all values for the combo boxes and the text boxes. I have successfully gotten the textbox values to clear although not the combo boxes. Any help is greatly appreciated.

  • Re: Reset Combobox Value


    I attempted to utilize your suggestion but with the same results. I do not know how to beat this. Any other ideas. I have included the actual code I am using to try to accomplish this. Again any help is appreciated.


  • Re: Reset Combobox Value


    You're getting that error because your mixing different data types...


    For instance this will result in a null val error...


    Code
    Private Sub cmbIceDrift_Change()
        txtIceDriftEncoded.Text = cmbIceDrift.Value
    End Sub


    ...and this fixes it:

    Code
    Private Sub cmbIceDrift_Change()
        txtIceDriftEncoded.Text = cmbIceDrift.Text 
    End Sub


    Try to set values-to-values and text-to-text and you'll be fine.

    [SIZE="1"]Sub All_Macros(Optional control As Variant)[/SIZE]

  • Re: Reset Combobox Value


    Thanks a million Aaron. I knew there must be something simple that I was doing wrong. Although I did not realize that mattered text or value. I am still learning a lot about correct coding practices. Again thanks for all of the help.

  • Re: Reset Combobox Value


    Quote from mikerickson;409095
    Code
    ComboBox1.Clear


    Sometimes these answers don't contain quite enough information. By the time I stop to ask, I've already tried numerous things and am tearing my hair out.
    Here, for instance, don't I need Me. before the combobox name? Can you explain why or why not? I'm getting my .Clear highlighted and the message 'method or data member not found'.

  • Re: Reset / Clear ComboBox


    Welcome to Ozgrid, E Van.


    Please do not post questions in threads started by other members. Start your own thread, give it a clear and concise title and explain your issue fully.


    If this thread can help clarify your problem you can include a link by copying the URL from the address bar of your browser and pasting into your message.

Participate now!

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