Listbox Hightlight / Selected (1 Viewer)

sznsx

Registered User.
Local time
Today, 02:17
Joined
Jul 25, 2004
Messages
20
I have been looking all around these forms and cant get any answer !

I have a listbox on a form that is part of a record selecting process. When the form first opens, no items in the listbox are highlighted. I need a way to make the first item in the listbox highlighted when the form first opens.

I have come across a few solutions such as: Me.lstCategory.Selected(0) = True

However these solution only VISUALY highlight the selected item. It may be highlighted but you cannot get a value returned from it. I determined this because I have other objects that run queries based on the selected item in the listbox, and they are not computing any values. Only after I phyiscally click on the highlighted item, do other values get computed.


Any ideas? Thanks !
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 06:17
Joined
Jul 9, 2003
Messages
16,245
Is it the clicking that activates the recalc though?
 

sznsx

Registered User.
Local time
Today, 02:17
Joined
Jul 25, 2004
Messages
20
Yes

Yes, by clicking on the item in the listbox, the other values are calcuated. I believe that the code only visually highlights the items, therefore I need code that actually selects the item.
 

pono1

Registered User.
Local time
Yesterday, 23:17
Joined
Jun 23, 2002
Messages
1,186
sz,

If it's always the top item, then you can grab the value doing something similar to this...

Code:
'Get the top item's value.
   Dim MyValue
   MyValue = List0.ItemData(0)

'Test
   Debug.print myvalue

Warning: If your listbox's column heads are enabled, then grab the top item as follows...
Code:
  MyValue = List0.ItemData(1)

Regards,
Tim
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 06:17
Joined
Jul 9, 2003
Messages
16,245
sznsx said:
not computing any values. Only after I phyiscally click on the highlighted item, do other values get computed.
Any ideas? Thanks !

The value you require highlighted is highlighted correctly, but the code associated with the on click event of the list box is not activating. This is because you haven't instructed the on click event to activate. If you have a look at the the attached example you can see that if you click on a number in the list box, then you activate the click event which displays the number you clicked on in a message box. However if you click on the command button, it only sets the value to 4 and does not activate the click event. What you'd need to do is it either call the click event when you load your form, or put the code associated with the click event into a separate routine and call that, both will work.
 

Attachments

  • ForumAns.zip
    12.8 KB · Views: 205

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 06:17
Joined
Jul 9, 2003
Messages
16,245
If you have a look at the example attached the form load event now selects the number 4 and calculates the values and places them in the answer text box. I think this is the sort of result you were after.

Strangely , I didn't have to call the click event of the list box, it was called when I selected a number in the list box with the on load event of the form.
 

Attachments

  • ForumAns2.zip
    13.4 KB · Views: 200

sznsx

Registered User.
Local time
Today, 02:17
Joined
Jul 25, 2004
Messages
20
Ok

Thank you for your post's I will take a look at them and report my findings !!!
 

Users who are viewing this thread

Top Bottom