PC Review


Reply
Thread Tools Rate Thread

Alphabetize a combo box list?

 
 
=?Utf-8?B?RGFu?=
Guest
Posts: n/a
 
      8th May 2007
Anyone got code that will put the items in a combobox in alphabetical order?

Thanks!

Dan
 
Reply With Quote
 
 
 
 
Steve Yandl
Guest
Posts: n/a
 
      9th May 2007
Dan,

In Excel, I've always used a rowsource that was a sorted list somewhere in
my workbook so the items didn't need to be sorted again. However, here is a
modified version of something I've used in a Word subroutine. The routine
below populates combobox1 found in a userform at the time the userform is
activated.

_____________________________

Private Sub UserForm_Activate()

Const adVarChar = 200
Const MaxCharacters = 255

Dim myArray As Variant
Dim myItem As Variant

myArray = Array("Tom", "Dick", "Harry")

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "myComboList", adVarChar, MaxCharacters
DataList.Open

For N = 0 To UBound(myArray)
DataList.AddNew
DataList("myComboList") = myArray(N)
DataList.Update
Next N

DataList.Sort = "myComboList"

DataList.MoveFirst
Do Until DataList.EOF
ComboBox1.AddItem (DataList.Fields.Item("myComboList"))
DataList.MoveNext
Loop

End Sub

____________________________

Steve Yandl


"Dan" <(E-Mail Removed)> wrote in message
news:0110412F-4597-4233-85A1-(E-Mail Removed)...
> Anyone got code that will put the items in a combobox in alphabetical
> order?
>
> Thanks!
>
> Dan



 
Reply With Quote
 
=?Utf-8?B?RGFu?=
Guest
Posts: n/a
 
      5th Jun 2007
Steve -
Thanks so much. I was able to modify your code and get it incorporated in to
mine, and it does the trick. I have never used a recordset before, so I am
learning something new.
Dan

"Steve Yandl" wrote:

> Dan,
>
> In Excel, I've always used a rowsource that was a sorted list somewhere in
> my workbook so the items didn't need to be sorted again. However, here is a
> modified version of something I've used in a Word subroutine. The routine
> below populates combobox1 found in a userform at the time the userform is
> activated.
>
> _____________________________
>
> Private Sub UserForm_Activate()
>
> Const adVarChar = 200
> Const MaxCharacters = 255
>
> Dim myArray As Variant
> Dim myItem As Variant
>
> myArray = Array("Tom", "Dick", "Harry")
>
> Set DataList = CreateObject("ADOR.Recordset")
> DataList.Fields.Append "myComboList", adVarChar, MaxCharacters
> DataList.Open
>
> For N = 0 To UBound(myArray)
> DataList.AddNew
> DataList("myComboList") = myArray(N)
> DataList.Update
> Next N
>
> DataList.Sort = "myComboList"
>
> DataList.MoveFirst
> Do Until DataList.EOF
> ComboBox1.AddItem (DataList.Fields.Item("myComboList"))
> DataList.MoveNext
> Loop
>
> End Sub
>
> ____________________________
>
> Steve Yandl
>
>
> "Dan" <(E-Mail Removed)> wrote in message
> news:0110412F-4597-4233-85A1-(E-Mail Removed)...
> > Anyone got code that will put the items in a combobox in alphabetical
> > order?
> >
> > Thanks!
> >
> > Dan

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alphabetize a list DRod Microsoft Word Document Management 1 3rd May 2010 09:09 PM
last name alphabetize Outlook mailing list as in address list =?Utf-8?B?UGF0Qw==?= Microsoft Outlook Contacts 1 1st Sep 2005 11:43 PM
Alphabetize Combo Box =?Utf-8?B?S2FyZW41Mw==?= Microsoft Access Form Coding 0 27th Apr 2005 11:39 PM
RE: Alphabetize Combo Box =?Utf-8?B?am9rb2Jl?= Microsoft Access Form Coding 0 27th Apr 2005 11:19 PM
Re: Combo Box alphabetize Dan Artuso Microsoft Access Forms 0 15th Jul 2003 04:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 AM.