How do you make a ComboBox display text and not the Primary Key ID?

E

Elizabeth

I have a form I'll call "Select Sources" in which I want
to include a ComboBox called Source. (The selection the
user makes will determine the source to include in a
report.) I want the ComboBox to display only the Sources
that have been added to the MainTable when the user adds
records.

In the ComboBox, it displays the SourceID stored in
MainTable. However, this isn't what I want. How can I get
my ComboBox to display the text associated with the
SourceID?

TableName: MainTable
Field: SourceID (Data Type = Number)
RowSource: SELECT Sources.SourceID, Sources.Source FROM
Sources;

In the MainTable, the SourceID is stored in the SourceID
field, but when you click on SourceID it shows you the
Source (text) - not the SourceID - which is as it should
be.

Table Name: Sources
Field: SourceID (Data Type = Autonumber)
Field: Source (Data Type = Text)

MainTable and Sources are joined on SourceID.

Thanks in advance,
Elizabeth
 
B

Bruce M. Thompson

In the ComboBox, it displays the SourceID stored in
MainTable. However, this isn't what I want. How can I get
my ComboBox to display the text associated with the
SourceID?

TableName: MainTable
Field: SourceID (Data Type = Number)
RowSource: SELECT Sources.SourceID, Sources.Source FROM
Sources;

Your combo box should contain 2 columns: the SourceID and Source fields, and in
that order. Simply set the following properties for the combo:

Bound Column: 1
Column Count: 2
Columnwidths: 0";2.5"
(You can set the second value to whatever width will better display
your field's value)
List Width: 2.5"
(This property should be the sum of all the column widths)
 
D

Dirk Goldgar

Elizabeth said:
I have a form I'll call "Select Sources" in which I want
to include a ComboBox called Source. (The selection the
user makes will determine the source to include in a
report.) I want the ComboBox to display only the Sources
that have been added to the MainTable when the user adds
records.

In the ComboBox, it displays the SourceID stored in
MainTable. However, this isn't what I want. How can I get
my ComboBox to display the text associated with the
SourceID?

TableName: MainTable
Field: SourceID (Data Type = Number)
RowSource: SELECT Sources.SourceID, Sources.Source FROM
Sources;

In the MainTable, the SourceID is stored in the SourceID
field, but when you click on SourceID it shows you the
Source (text) - not the SourceID - which is as it should
be.

Table Name: Sources
Field: SourceID (Data Type = Autonumber)
Field: Source (Data Type = Text)

MainTable and Sources are joined on SourceID.

Check the combno box's ColumnWidths property. The combo will display
the first *visible* column; i.e., the first column whose width is > 0.
So if you have two columns and want to display the second one, set the
ColumnWidths property to something like

0";1"

(or whatever width is appropriate for the column).
 
W

Wayne Morgan

You have both pieces of information in your Row Source, which is how it
should be. The fields in the Row Source will be displayed (left to right) as
they are in the Row Source. The combo box will display all visible columns
in the drop down, but only the first visible column in the textbox portion.
Set the column width of the undesired column to zero (ex. 0;0.5). This will
hide the number column and leave the text column for the user. The Bound
Column should be the one with the ID (in this case 1) and the Control Source
should be the ID field in the main table.
 
E

Elizabeth

Thank you, Bruce, Dirk and Wayne. I'm afraid I still
don't understand what's happening or what I should do
since I think I've done everything each of you have
instructed.

When I created my table, I used the wizard to create a
lookup, and told it to get the SourceID and Source. When
data is entered into the table, the Source appears and
the SourceID is hidden.

In the form, I also used the wizard to create the
ComboBox, and told it to display Source. When it comes
to "How wide would you like the columns in your ComboBox
to be, I have "Hide Key" checked. If I look at the sample
information, it shows the Primary Key of the Primary Key
of MainTable, and Source displays the SourceID. This is
actually correct, since I have stored the SourceID in
Source. But what I want to happen is to display Source
(the text associated with SourceID)from the Sources
table. So, are you saying I should store the SourceID AND
the Source (text) in my MainTable, which doesn't make
sence and I thought you weren't supposed to do that.
Would it be easier just to store Source in my table and
forget about the SourceID? I'm completely confused!

Elizabeth
 
W

Wayne Morgan

No, you wouldn't store both in your main table, just the SourceID. Open the
form in design mode and double click the combo box to open its properties
sheet. What does it have listed for the following (I know you've already
mentioned some of these, they should all be on the Format or Data tab):

(Data tab)
Control Source
Row Source Type
Row Source
Bound Column
(Format tab)
Column Count
Column Widths
 

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