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

Retreiving value from List Box 2

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
US
Hi, I have a query that populates a list box:
Code:
    strSQL = "SELECT [tblSite-Type].[User Entered], [tblSite-Type].[Site ID], [tblSite-Type].[Superfund Site] "
    strSQL = strSQL & "FROM [tblSite-Type] "
    strSQL = strSQL & "ORDER BY [tblSite-Type].[Site ID], [tblSite-Type].[Superfund Site];"
    Me.listSitesEdit.ColumnCount = 3
    Me.listSitesEdit.ColumnHeads = True
    Me.listSitesEdit.RowSourceType = "table/query"
    Me.listSitesEdit.RowSource = strSQL

I'm trying to populate a text box with the value from the second column of the listSitesEdit listbox (which is [tblSite-type].[Site ID]. For some reason, It populates it with the first column value. Here's the code I have for trying to retrieve the value:

Code:
    If Me.listSitesEdit.ListCount > 0 Then
        For i = 0 To Me.listSitesEdit.ListCount - 1
            If i = Me.listSitesEdit.Selected(i) Then
             Me.txtSiteID.Value = Me.listSitesEdit.Column(i, 2)
            End If
        Next i
            
    End If

Not sure what I'm doing wrong
 

If I'm not mistaken, the first column is the bound column by default.
You need to include [blue]Me.listSitesEdit.BoundColumn = 2[/blue].

Make the control source of the text box [blue]=listSitesEdit[/blue].


Randy
 
try
Me.txtSiteID.Value = Me.listSitesEdit.Column(1, i)
 
Replace this:
If i = Me.listSitesEdit.Selected(i) Then
With this:
If Me.listSitesEdit.Selected(i) Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks everyone, getting closer. I've got it to loop through all the values, but the if statement is still not working (doesn't fire the msgbox):
Code:
    If Me.listSitesEdit.ListCount > 0 Then
        For i = 0 To Me.listSitesEdit.ListCount - 1
           If Me.listSitesEdit.Selected(i) Then
            MsgBox Me.listSitesEdit.Column(1, i)
           End If
            'MsgBox Me.listSitesEdit.Column(1, i)
           Next i
    End If
 
Got it -
if me.listSites.ListIndex = i
 
If the ListBox is a MultiSelect one, you may have to play with the ItemsSelected collection.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top