selecting the first row in a listbox programaticly

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having a problem with list boxes. what I want to do is when a new item
has been added to a listbox I need to make it the selected item
programaticaly. Ive tryed many different bits os code but with no luck. can
anyone help??

thanks Marcel
 
The example below shows two ways. The commented-out line simply assigns the
newly added value to the Value property of the list box. The line below it
uses the ItemData and ListCount properties to determine the ordinal position
of the item in the list. This assumes that the item was added to the end of
the list. If you add the item to the beginning of the list, you can simply
use ItemData(0).

Option Compare Database
Option Explicit

Private Sub Command4_Click()

Me.List2.RowSource = Me.List2.RowSource & ";" & Me.Text0
'Me.List2 = Me.Text0
Me.List2 = Me.List2.ItemData(Me.List2.ListCount - 1)

End Sub

Private Sub Form_Load()

Me.List2.RowSourceType = "Value List"
Me.List2.RowSource = "one;two;three"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top