Results 1 to 9 of 9

Thread: VBA Combo Box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    484

    VBA Combo Box

    Dear all,

    I am having a bad time on clearing existing items on a combobox.
    In VB.Net, I can just simply say Combobox1.clear, but this.....GOD.....kill me big time.

    Please help me.

    Thank you

    PlayKid

  2. #2
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Re: VBA Combo Box

    Combobox1.Value = ""

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    484

    Re: VBA Combo Box

    no use.....
    I tried

    Combobox1.Value = null
    Combobox1.Value = ""
    Combobbox1.Value = nothing

    All of them not working.

  4. #4
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Re: VBA Combo Box

    What application are you using, Excel?
    The code on a Userform would be
    Code:
    Me.ComboBox1.Value = ""
    This would normally be used when reseting/clearing the Userform

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    484

    Re: VBA Combo Box

    Access 2000...
    I try to use a loop, but I can't find another component again, that's "Count", trying to remove all items on the combobox...
    Anything I can think of that I can program easily in .Net, or VB6, does not work on VBA.....GOD................

  6. #6
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: VBA Combo Box

    Hi!!!

    Is your combo box's row source type value list or field list or table/query?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    484

    Re: VBA Combo Box

    Value list

  8. #8
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA Combo Box

    You need to remove each item from the combobox one by one. Also, you need to do this in reverse order to ensure integrity between your loop counter and the ListIndex.

    The following snippet will clear a combobox of all values, even when a value has been selected.

    VB Code:
    1. Dim lListIndex As Long
    2.    
    3.     With Me.Combo3 'Change to your combobox name
    4.         .SetFocus
    5.         For lListIndex = .ListCount - 1 To 0 Step -1
    6.             .RemoveItem (lListIndex)
    7.         Next lListIndex
    8.         .SelText = ""
    9.     End With
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  9. #9
    New Member
    Join Date
    Feb 2006
    Posts
    14

    Re: VBA Combo Box

    Please ignore this if it's resolved.

    ...
    ...
    Combobox1.Object.Value = ""
    ...
    ...
    will clear the text in the box.
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width