Re: Combobox Sorting



LondonLad wrote:
Hi
I am using this code provided by MikeD and I want to sort the Combobox entries so I added the line as shown **
This give an error "Can't assign to Read-Only property" How can I sort the Combobox? can you help please

Private Sub Form_Load()
Dim lFileNum As Long
Dim sFileName As String
Dim saItems() As String
Dim sTemp As String
Dim Index As Long

On Error GoTo EH

cboTest.Text = "Select Item"
cboTest.ListIndex = -1
**
cboTest.Sorted = True
**
txtItemToAdd.Text = ""
cmdAdd.Enabled = False

If Right$(App.Path, 1) <> "\" Then
sFileName = App.Path & "\" & CBO_LIST_FILENAME
Else
sFileName = App.Path & CBO_LIST_FILENAME
End If

lFileNum = FreeFile

'Be prepared for a file not found error
Open sFileName For Input As lFileNum
sTemp = Input(LOF(lFileNum), lFileNum)
Close lFileNum

saItems = Split(sTemp, vbCrLf)
For Index = LBound(saItems) To UBound(saItems)
If Len(saItems(Index)) > 0 Then
cboTest.AddItem saItems(Index)
End If
Next

Exit Sub

EH:

Close lFileNum
If Err.Number <> 53 Then
MsgBox Err.Description
End If

End Sub


open your program in the IDE and select the errant combobox on whatever form it's on.
Change the "Sorted" property in the combobox properties box to true.

As the message says "Can't assign to Read-Only property"

Any message that comes back with that, means you have to preset whatever control that generated it, via the property in the properties box when you're developing your program.

That's the simple fix.

There are other means to do what you want, but you need to be a VERY experienced programmer, in classing and exposing properties, to understand it.

I'm not, so if you're after that sort of programming, you need one of the MVPs in the forum to explain it. One of 'em will surface if you are prepared to wait.

Argusy




.



Relevant Pages

  • Re: Combobox Sorting
    ... A number of ways to sort this the easiest is to set ... the sorted property to true at design time. ... Private Sub Form_Load ... Open sFileName For Input As lFileNum ...
    (microsoft.public.vb.general.discussion)
  • Re: Combobox
    ... Private Sub ComboBox1_Change ... > Now go back to the worksheet, right-click the combobox again, select Assign ... > Macro, and assign the above macro to the combobox. ... >> a) sort a list by client ...
    (microsoft.public.excel.programming)
  • Passing a comboBox to a sub
    ... I am trying to pass a comboBox to a sub to carry out sort on the items, ... Sub BubbleSortCombo ... returns a type mismatch error I know it is to do with the different ...
    (microsoft.public.excel.programming)
  • Re: CBS_SORT / LBS_SORT, what algorithm?
    ... They also suggest maintaining the sort outside the ComboBox/ListBox control and populate the result to ComboBox/ListBox without SBC_SORT. ... Inside ComboBox, it always uses "Insertion Sort" when SBC_SORT is specified, and a re-sort + re-add of the whole list is also done internally when users add / edit the list items. ... We welcome your comments and suggestions about how we can improve the support we provide to you. ...
    (microsoft.public.win32.programmer.ui)
  • Re: Sort order via excel userform combobox
    ... It sounds like you have one column for each combobox. ... Is there a reason why you ... just can't sort just column A in ascending order, then sort just column B, then ... that Column C is now sorted in ascending order. ...
    (microsoft.public.excel.programming)