get a value from a list box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a list box on a form to enter data. The list box is refreshed vie
requery when the user leave another control. I always show the choices in the
list box for the current record plus "other item" by having this as an
alternative in the query for the list box. I want to automatically enter the
value from the list box if there is only onr alternative to the "other item"
and can't seem to make it happen. (i am running a query similar to the one
for the list box and counting the records using If record count =2 then
value=listbox value but nothing happpens. I think I need to get the value
into the list box somehow without clicking it. any assistance would be
appreciated
Mike
 
One way to do this would be to use a function procedure as the data
source of the listbox. You can do whatever you want in that function
procedure, to determine what entries you want to display. So if you
determined that there was only one true entry, you would just supply
that entry. But if you determined that there were several true entries,
you could add the "other item" entry, through code, in that procedure.

Do a search of Access Help for LB_INITIALIZE or LB_END. That should
find the relevant info.

HTH,
TC
 
Thanks but what I want to do is enter the value displayed in the text box in
the underlying table if there is only one item displayed apart from the
"other" which is automatically shown in the list box.
 
I don't understand. Why do you want to write a single value into the
field, automatically, if the listbox has another entry ("other") that
the user might have chosen instead?

Either: (1) the listbox has >1 entry, in which case, you should wait
for the user to select the right one; or (2) the listbox only has 1
entry, in which case, Access will /automatically/ write that value into
the field, when it saves the dirtied record.

?

HTH,
TC
 
Back
Top