Full Version: Combo Box Problem
UtterAccess Forums > Microsoft® Access > Access Forms
mstavrop
Hi all,
I'm trying to make the following thing. Use a combo box to select a name from a table and store that name in an another field on the same form. The problem is that when i select the name from the combo instead of that its stores the Primary key (ID) of the selected person. What I'm doing wrong? Any suggestions please? crazy.gif
ScottGem
You aren't doing anything wrong. You just need to understand how comboboxes work. When you use the wizard to create a combobox, by default it sets it up to store the Primary key value but display the name. It does this, by setting the width of the first column to 0". Check the column widths property and you will see what I mean. The bound column will be column 1, the primary key.
This is the way it should work. Since the Primary key is normally meaningless to the user, there is no reason to display it. So your combobox should display the name and there should be no reason to put it in another control. This is a key concept here. The ONLY thing you need fromt he table where you are selecting the name IS the Primary key value. This is your foreign key. With the foreign key you can join the two tables and get any data you need from the related table.
Hope this helps,
neboland
I am having a similar problem, but I don't want the primary key from the combo box in another field, I want to return a string equal to the text in the second column
How do I do this
S_R_T
good question, i want the same thing to
Ohoping that one fo the pros would help is out
wen
Just set the property Bound column to the right value.
E.g. if you have a SELECT of the PK followed by a Name column and you want the value of the latter, set the property to 2.
See the attachment for an example.
HTH, Wen
NoahP
If you are storing the text in another table, your table structure is probably not normalized. You should be storing the Primary Key, not the text. You can get the text via the relationship any time it's needed. That is what a relational database is all about.
oah
ScottGem
If you read my initial response in this thread it explains how this works. As Noah and I have said, you do NOT want to store that text string. The main purpose of a relational database is to reduce redundant informatioin. One of the ways this is done is to put repeated information into a separate table and then use the key fields to join the tables.
There is NO need to put any value other then the primary key (as a foreign key) in the related table!!!!
Ocan't emphasize that enough. This is how you properly construct a relational database. This is why the combobox wizard in Access defaults to adding the Primary key as the bound and hidden column.
neboland
I understand the purpose of the relational database. Perhaps I should explain my problem
I am creating a database of scientific literature references. One of the fields in my form is a combo box where the user will select a Journal Title. At the very end of the form I have a button that takes the information in the form and copies it to the clipboard - however, it copies the primary key from the Journal combo box. I need it to copy the text string from the second column in that table that is associated with that primary key.
I appreciate your patience and your assistance. I appologize for not clearly stating my need previously.
ScottGem
Ahhh. I'm not sure why you want to copy to the clipboiard or what purpose it serves. Might have helped if you explained that.
But assuming you are not trying to store the text value anyplace, you can use the Column property to get the text value. Assuming the text you want is in the second column of the query behind the comob you can use:
x = Me!comboname.Column(1) Column count starts at 0
Hope this helps,
neboland
Thank you! It worked...
HAs for the clipboard - I want to be able to take a reference (with a given format - but I will get to that problem) and use it in a word document. My solution was to take all of the values and put them in an array then use the join command and export to the clipboard.
Fearing that I am taking this string in another direction - is there a way to apply format to my string (ie. bold, italics, etc.) so that it pastes from the clipboard correctly?
ScottGem
I don't think you want to use the clipboard for this. I think you would be better off using bookmarks. You might check out this article for tips on how to do this.
Hope this helps,
P.S. If you want to pursue this further I suggest starting a new thread.
mstavrop
I finally found out another way to do the same thing using Dlookup function and its working fine!
Thank you all for your help! thanks.gif thumbup.gif
S_R_T
In order for myself and the other new users that are driving you professionals nuts, let me put this
barnie style
On the form ( it will display the text because the primary key means NOTHING TO THE USER
when you openthe table in datasheet view
you will see the
PRIMARY KEY
becuase the primary key means alot to ACCESS.
Obelieve this is right, someone correct me if i am wrong.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.