I just tried this out, and I found that (and this is not even mentioned in Help) if the MultiSelect property is set to None, the method you employed (which is the same method found in the Help example) of looping through the listbox's Selected array doesn't work.
Instead, you can return the Value of the item chosen in the ListBox by simply referencing the Value property (which, by the way is always Null if the MultiSelect property is set to Simple or Extended instead of None). If the MultiSelect property is set to Simple or Extended, then the method you employed works fine. So, assuming you only want to select one item in the listbox at a time, your code should look like this: Private Sub ListCollections_AfterUpdate() Dim cnn As ADODB.Connection Set cnn = CurrentProject.Connection Dim rs As ADODB.Recordset Dim sql As String Set rs = New ADODB.Recordset sql = "select startdate,enddate from collections where collectionid = " & CStr(ListCollections.Value) rs.Open sql, cnn CalAltCollec1.Value = rs(0) CalAltCollec2.Value = rs(1) End Sub HTH, Toby ----- Original Message ----- From: "bitschon" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Thursday, September 22, 2005 4:36 PM Subject: [AccessDevelopers] Get the value of a list box at N when clicked > I'm trying the return the value of a row in a listbox when clicked. > > This code looks like it should work to return the value at the > selected row, but it doesn't: > > Private Sub ListCollections_AfterUpdate() > Dim ctr As Integer > Dim cnn As ADODB.Connection > Set cnn = CurrentProject.Connection > Dim rs As ADODB.Recordset > Dim sql As String > > Set rs = New ADODB.Recordset > MsgBox ListCollections.Selected(0) > > For ctr = 0 To ListCollections.ListCount - 1 > If ListCollections.Selected(ctr) = True Then > sql = "select startdate,enddate from collections where > collectionid = " & CStr(ListCollections.Value) > rs.Open sql, cnn > CalAltCollec1.Value = rs(0) > CalAltCollec2.Value = rs(1) > End If > Next > > End Sub > > It never enters the IF statement. > > How do I do this? > > Thanks > > JOS > > > > > > > Please zip all files prior to uploading to Files section. > Yahoo! Groups Links > > > > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> Fair play? Video games influencing politics. Click and talk back! http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/q7folB/TM --------------------------------------------------------------------~-> Please zip all files prior to uploading to Files section. Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/AccessDevelopers/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
