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

Selected Item Listbox-Simple 1

Status
Not open for further replies.

Christineeve

Programmer
Feb 12, 2005
104
US
Hi!
I've done this before but for some reason today, I can't find my old source code, and bonus...I'm having a mental block and can't figure this out.

I'm trying to simply return one item that is selected in a listbox. I need to eventually pass it into my query, but I feel confident I can do that part.

When I select my date on the form, #07/31/2009#, this code goes to the first line entry in the control and returns that date, not my selected date. In this case #12/31/2006, instead of 7/31/2009.

I should know why but I don't. I feel foolish in asking because I'm sure it's obvious, but I'm overlooking the problem. Am I missing a count to increment?

Thanks for any help. I appreciate your help.

Here's my code:
'CMD is the name of the listbox control
'It's improper naming convention, I'm stuck with it.
'I'm developing a report that piggybacks off
'this existing stuff.

Dim lngcloop As Long

For lngcloop = 0 To (Me.CMD.ListCount - 1)
Me.CMD.Selected(lngcloop) = True
strCurrentMDate = Me.CMD.ItemData(lngcloop)
Exit For
Next lngcloop

MsgBox strCurrentMDate
 
You wanted this ?
Code:
For lngcloop = 0 To (Me!CMD.ListCount - 1)
  If Me!CMD.Selected(lngcloop) = True Then
    strCurrentMDate = Me!CMD.ItemData(lngcloop)
    Exit For
  End If
Next lngcloop

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
Yes, this is perfection. Thanks so much for helping me. I've given you a star.

Best regards,
Christine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top