Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding items at the top of a list box

Status
Not open for further replies.

Ca1icoJack

IS-IT--Management
Nov 27, 2008
36
GB
How can I add items to the top of a list box rather than the bottom?

I want to type in a word and then click a button which does this in a user form.

Thanks in advance
 
Hi,

What application? If it's MS Access, then post your question in forum705.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Its for Excel. Although since its adding within a userform why would it make a difference?
 


How did you assign the rowsource to begin with?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
The source of each item is a text box above.

So my code is currently:

________________________________________________________

Private Sub CommandButton1_Click()

UserForm1.ListBox1.AddItem (UserForm1.ListBox1.Value)

End Sub
________________________________________________________

I assume it would be something like the following, although that simply overwrites the top row.
________________________________________________________

Private Sub CommandButton1_Click()

UserForm1.ListBox1.List(0,0) = UserForm1.ListBox1.Value

End Sub
_________________________________________________________
 
If you had Auto Quick Info enabled (whicyh it is by default) in the IDE you should see that AddItem can take a second parameter which indicates where in the list the item is added.

The help file is also worth consulting on this.
 
pvargIndex is shown but what value should I put for it?

I tried the following originally, but the text always turns red, is there something else I need to do to make this work?
________________________________________________________

Private Sub CommandButton1_Click()

UserForm1.ListBox1.AddItem (UserForm1.ListBox1.Value, 0)

End Sub
________________________________________________________
 
Nevermind... Brackets were causing the problem.

Thanks very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top