Full Version: Bound Listbox, With Only 2 Choices
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
ipisors
I have a table with a field called Channel.

I only want there to be 2 possible values in this field, which will come from a data entry form that various users will access. the two possible values I want to be RELS and Bank Direct.

Having been advised before on this forum that it was better to avoid using some of the trickier field datatypes in the Table design (like lookup or combo/list), and instead address them at the point of data entry,...which kind of made sense to me because having table fields whose design was something like that tended to complicate the running of queries........I have the field as simply Text type in the table.

But I want on my data entry form to have a combobox or listbox (I was thinking listbox so the users can always see the values displayed as choices, and there are only 2 anyway). I'm a little confused on how to do this.

I created an unbound listbox on my form, then changed its record source to the field Channel but then when I added code:

CODE
Private Sub listchannel_Enter()
Me.listchannel.AddItem "Bank Direct", 1
Me.listchannel.AddItem "RELS", 2

End Sub
it told me the record source type had to be changed to Value List, which makes it unbound again.

How do I get users to only choose from 2 options to put in this field, without changing table design?

PS. I mean I could use checkboxes or something, but that wouldn't be bound to anything and would require some additional coding that I'm uncertain of, to get the value in the table field at the same time the form updates everything else which is all bound.
Doug Steele
I think you may have misinterpretted the error message you got. It was telling you to change the RowSourceType property to Value List (from the default Table/Query setting). That shouldn't change the list box from bound to unbound.

That being said, I don't understand why you would bother using code to set the choices if they're always going to be the same. Set the list box once, and leave it.
ipisors
I guess my confusion is how do I make a listbox, bound to the table where the values are going into, but only with 2 possible choices.
Doug Steele
Easiest way is to use the wizard.

Failing that, do the following:
  1. Add a list box to the form
  2. Set its ColumnCount property to 2
  3. Set its RowSourceType property to Value List
  4. Set its RowSource property to Bank Direct;1,RELS;2
  5. Set its ControlSource to the name of the column to which you which to bind it
ipisors
when I used the wizard, none of the options, worded as such, were obvious to me as being what I needed so I was not sure if I was doing it right. Thanks for the bullet list, that gets my understanding further than the wizard. I just needed to understand clearly that ControlSource was were the data was going (bound to), and everything relating to Row- had to do with the options that would appear in the box.

As always thanks Doug!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.