Annoying Listbox Quirk

J

John

Using Access 2007 I find that, on opening a form, a listbox control
always displays one of the values in the list, even if no value has
been selected. Thus, the first value in the list is displayed
(without highlighting) when the field has a null value. The user may
then change the displayed value by clicking on the up or down arrow to
the right of the control. This newly displayed value will also be
without highlighting and will be unselected. No value will actually
be selected until the user clicks on the displayed value or tabs
through the control while that value is displayed. I assume the lack
of highlighting is supposed to signal that the displayed value has not
been selected. However, my users don't know this and if the
unhighlighted value displayed in the list box happens to be the one
they want, they just save the record without ever clicking on or
tabbing through the listbox control. As a result, a null value is
stored in that field and the user is hopping mad that his "data entry"
didn't work.

I have worked around this by hooking a subroutine to the "On Save"
form event to check for a null value in the field referenced by the
listbox control. A message box tells the user he/she must click on
the value displayed in the listbox control to "select" the item they
think they have already chosen. This is pretty lame.

Ideally I should be able to programmatically check to see which item
is displayed (even if unselected) and, simply write that value to the
appropriate field when the record is saved without bothering the
user.

I can use the ItemData property of the listbox object to read the
values of the various items in the list, but I can't find any property
which tells me which of these values is currently being displayed.

Extensive Googling has been unsuccessful in yielding an answer. Any
suggestions would be appreciated.

John
 
A

AccessVandal via AccessMonster.com

Hi,
John wrote:
Using Access 2007 I find that, on opening a form, a listbox control
always displays one of the values in the list, even if no value has
been selected. Thus, the first value in the list is displayed
(without highlighting) when the field has a null value. The user may
then change the displayed value by clicking on the up or down arrow to
the right of the control. This newly displayed value will also be
without highlighting and will be unselected. No value will actually
be selected until the user clicks on the displayed value or tabs
through the control while that value is displayed. I assume the lack
of highlighting is supposed to signal that the displayed value has not
been selected. However, my users don't know this and if the
unhighlighted value displayed in the list box happens to be the one
they want, they just save the record without ever clicking on or
tabbing through the listbox control. As a result, a null value is
stored in that field and the user is hopping mad that his "data entry"
didn't work.

Use Combo box instead of List box. Bound the combo box to the recordsource.
I have worked around this by hooking a subroutine to the "On Save"
form event to check for a null value in the field referenced by the
listbox control. A message box tells the user he/she must click on
the value displayed in the listbox control to "select" the item they
think they have already chosen. This is pretty lame.

You don't need to create a subroutine, you can use the form's event procedure
to handle this, like AfterUpdate or AfterInsert.
Ideally I should be able to programmatically check to see which item
is displayed (even if unselected) and, simply write that value to the
appropriate field when the record is saved without bothering the
user.

With combo box, the user doesn't need to key the value.
I can use the ItemData property of the listbox object to read the
values of the various items in the list, but I can't find any property
which tells me which of these values is currently being displayed.

Same as above.
 
J

John

Hi,




Use Combo box instead of List box. Bound the combo box to the recordsource.


You don't need to create a subroutine, you can use the form's event procedure
to handle this, like AfterUpdate or AfterInsert.


With combo box, the user doesn't need to key the value.


Same as above.

Vandall,

Good reference on the listbox. It looks, however, like it just
doesn't have the functionality I was hoping for.

The reason I avoided the combobox was my desire to limit the user to
selecting an item within a list. I don't want to give them the option
of adding a new item. I could, of course, write some code to go in
the Before Update event of the combobox control to do this. Maybe
this is the simplest way to go. Or is there a combobox property which
limits the user to selecting from the list? Thank would be
convenient.

Appreciate your help.
 
A

AccessVandal via AccessMonster.com

Hi John,

Combo box is capable of limiting selected items and if you want to add a new
item, you can use the "NotInList" event.

You can also use the "NotInList" event to control the user input by a message.
 
K

Ken Snell \(MVP\)

John said:
The reason I avoided the combobox was my desire to limit the user to
selecting an item within a list. I don't want to give them the option
of adding a new item.

Set the LimitToList property of the Combo Box to Yes. That will prevent any
addition by the user.
 

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

Top