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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select the first row in a list box with vba and get the value?

Status
Not open for further replies.

danielhis

IS-IT--Management
Nov 18, 2003
5
0
0
AU
I have a list box with records and when a user clicks on contine I want the first row to be automatically selected and the value of the the first column in that row to be appended to a table. When I use the following code, the first row is seen to be selected on screen but the value comes up as null so I get an error in the append part of the code.

Lst.Selected(0) = True

Val1 = Lst.Value (or Val1 = Lst.column(0) - doesn't matter)

If I physically select the first row with the mouse, it works.

Any Ideas?

 
To fix this don't select the item using

lst.Selected(0) = True.

Instead select it using the ItemData method like this.

lst.Value = lst.ItemData(0)

Hope this helps!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top