Default Selection in a Listbox Problem

J

JP

I have a form with a listbox on it. Neither the form nor the listbox is
bound to any table or query (the form is a main menu kind of form, and the
contents of the listbox are the various program functions).

The row source for the listbox is a query against a table. When this form
displays, I want to default select the first item in the listbox (i.e.,
actually have it highlighted). To do this I put code in the Open event for
the form as follows:

Me.lstMenu.Selected(1) = True

(Note that the listbox does display column heads, so that the first row of
actual data is row 1 instead of row 0)

This highlights the first line of data. HOWEVER, when I have this code in
there, nothing on the form works. I can't click on any of the command
buttons, I can't select some other item in the list box, I can't type into
any of the text boxes -- just nothing works.

Anyone have any ideas as to why this is happening? Is there a
better/correct way to default an item in a listbox?

Thanks in advance.
 
P

Penguin

Try inserting this in the OnCurrent property of the form:

Me!lstMenu = Me!lstMenu.ItemData(1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top