473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

getting a combo box to store multiple values

Hi,

I am setting up a database and would like a combo box on a form to store two values. for example, there's a ID and a Description. I can easily get the combo box to show both the ID and the Description. however the combo box is tied in to one field only, in this case, the ID.

I'd like the form to store both the ID and then display the Description in a field next to the ID.

your assistance is much appreciated, thanks!

Todd
Apr 23 '09 #1
32 22099
NeoPa
32,556 Expert Mod 16PB
I'm not sure what you're asking Todd.

Your explanation seems to contradict anything I think you're asking :S
Apr 23 '09 #2
sorry about that!

i've built a form that needs to store hotel ID, hotel with other client info. the hotel id and hotel are stored in a seperate table. when the combo box is opened, hotel id and hotel appear in the pull down. however b/c the combo box is built on a field controled by hotel ID, only the hotel ID is transferred to the form. the hotel field remains blank. i was going to build a macro and create an update query (im a GUI person) to update the hotel field but i'd prefer to build an expression that based on the hotel ID, can update the Hotel. hope that makes a little more sense.

thanks

todd
Apr 23 '09 #3
mshmyob
904 Expert 512MB
Use the 'column' parameter with the combobox value.

Expand|Select|Wrap|Line Numbers
  1. Me.txtYourTextBoxName = Me.cboYourComboName.Column(0)
  2. ' or
  3. Me.txtYourTextBoxName = Me.cboYourComboName.Column(1)
  4.  
Each column number refers to each column in your combo box.

Does this help

cheers,
Apr 23 '09 #4
NeoPa
32,556 Expert Mod 16PB
I'm sorry Todd. If all the words made perfect sense in sequence, the punctuation would possibly not matter so much. As it is, I can only guess which words are in the right place from the punctuation, which is missing or misplaced in most cases. Most of the words are probably wrong because you don't have a very good grasp of the terminology, which is quite understandable, but it makes taking care to punctuate and not drop random words, all the more important.

What do you have as the RowSource of your ComboBox (I'm assuming the pull down from one sentence is actually referring to the combo box from the next)?
What are the values for Column Count, Column Widths & Bound Column in your ComboBox control?
Apr 23 '09 #5
MSHMYOB,

sorry pls bear with me. when i create the combo box, i use the wizard therefore many of these underlying controls are not visible. what i do is i use the wizard to prepare the box. here are the steps:

1) wizard asks me the source, i tell it the hotel table
2) asks me which fields would i like to see in the pull down. i tell it hotel ID and hotel
3) asks me where i'd like this data stored. i tell it hotel ID.

is there a back end control or expression where i could tell it to do what you recommend?

thanks again
Apr 23 '09 #6
neopa,

we obviously have a communication barrier but i appreciate your dedication the the cause.

here are the current settings:

control source: Hotel ID
Row Source: SELECT Hotels.HID, Hotels.Hotel FROM Hotels;
bound column: 1

so from this:

"Control Source" is the Hotel ID and is the field on the form that is updated from the combo box
"row source" determines which fields are displayed in the combo box pull down
"Bound Column" is the field that gets stored

again, i'd like to store the both the hotel id and hotel however it doesnt seem to allow you to do that in the GUI.

Thanks NEO.
Apr 23 '09 #7
NeoPa
32,556 Expert Mod 16PB
There's certainly a way of finding the info I asked for.

If you view the form in Design mode, click on the newly created ComboBox control and select Properties (Alt-Enter will do this for you).
Look through the properties and note (& post) the values of the properties I requested.

A wizard is merely a way of doing ordinary designs more easily. What it produces can be done manually just as well (but not so easily for someone short of experience).

PS. Just caught your latest post and now processing...
Apr 23 '09 #8
Hi,

yes, i rarely design forms so i am pretty green...

here are those values, thanks!

Row Source: SELECT Hotels.HID, Hotels.Hotel FROM Hotels;
Column Count: 2
Column Widths: 0.3646";1.8646"
Bound Column: 1
Apr 23 '09 #9
NeoPa
32,556 Expert Mod 16PB
@tfurubay
I think you're starting to grasp some of the concepts here Todd.

I also think I've started to grasp what you're trying to ask (originally). If I'm not mistaken, you're asking how to get the ComboBox control to maintain two fields in the underlying recordset (that the form is built upon). Is that about the size of it?

If so, then I'm afraid that facility is not supported. There can be only one Control Source for the control. However...

It is possible to put some VBA code in the AfterUpdate event of the control, such that a separate control (bound to a separate field from the underlying recordset) is updated. Another however coming I'm afraid...

This is not a good idea as Normalised Relational Databases (Normalisation and Table structures) are designed to work differently. This would be de-normalising your data (which is not a great idea - trust me).
Apr 23 '09 #10
NeoPa
32,556 Expert Mod 16PB
Considering you are, as you say, pretty green, let me try to explain things in more layman terms :-

When you have linked data such as that (An ID & a linked description / name / etc) it is recommended that you don't try to store the linked information again (It should already be stored in your reference table - [tblHotel] or whatever you've called it). Rather, that you link to it whenever it's required. One of the main reasons for this is that otherwise you create a rod for your own back trying to ensure the data never slips out of step. There are other more complicated reasons (read the linked article for the full SP).
Apr 23 '09 #11
mshmyob
904 Expert 512MB
In the AFTERUPDATE event of your combo box put the following line in code (ie: code builder).

Expand|Select|Wrap|Line Numbers
  1. Me.txtYourTextControlName = Me.cboYourComboControlName.Column(1)
  2.  
Replace txtYourTextControlName and cboYourComboControlName with your text and combo control names.

cheers,

@tfurubay
Apr 23 '09 #12
mshmyob
904 Expert 512MB
My understanding from his 1st post is that he has a combo box that has 2 columns (Hotel ID and Hotel Name)

After selecting a hotel from the combo box he wishes to save the 2nd column value (Hotel Name) to a text control on his form.

If that is what he wants then a simple AFTERUPDATE event for the combo box to transfer column(1) from the combo box to the text control should do what he wants. (see my solution in previous post)

But I have been fooled before for what an OP wants :)

cheers,

@NeoPa
Apr 23 '09 #13
you hit the nail on the head. i am trying to control two fields with one combo box. i was hoping to put some vba code to grab the related field. i see where you're going with respect to normalization best practices. i see what you mean b/c let's say we change the hotel name, then my historical hotel names won't be updated. i can instead create the relationship and let the hotel ID always pull the current hotel. one for me to ponder. i guess i could bound the form to a query with all the links but my concern in doing so is the ability to update data direcly on the form.
Apr 23 '09 #14
NeoPa
32,556 Expert Mod 16PB
@mshmyob
I'm not sure who Todd is replying to in his latest post, but as we're both essentially saying the same thing here I suspect it doesn't matter too much. The upshot is clearly that your understanding is correct.

@Todd, This looks as if you have a reasonable understanding of the issue now. I'm not sure building the form over a query gives you much in this case, but your other comments make sense. As Mshmyob says, there is a way to handle your original request (you'll find pointers in posts from both of us on that if you look) but I suspect you will decide that's not too good a plan when you've thought it through.
Apr 23 '09 #15
both of you are spot on. thank you! i hope one day to help others as you do in my own little way.

neo if i designed this the optimal way, then how would i get the form to show the hotel? by building a subform and linking on hotel ID? the challenge is we are converting from excel to access so we have to stick with the current table formats in order to view historical data.

mysh, thanks i do understand the event procedure functions in the field settings. i may have trouble with the syntax so i may post one last time. i really want to thank both of you for everything.
Apr 23 '09 #16
NeoPa
32,556 Expert Mod 16PB
@tfurubay
As I understand it Todd, you already have a ComboBox designed that shows both the ID & the name of the hotel, with the ID being bound to the underlying data. This being the case, it will automatically show the related name whenever there is a valid ID in place. I'm not sure what else you would need (or want).

If the table formats somehow complicate the question, you will probably need to post what these formats are that we will need to consider.
Apr 23 '09 #17
neo, currently, i have one table linked to the form that stores hotel and hotel ID along with other customer info. Both are blank until someone selects hotel ID. i am stuck with this simple design. i can see the hotel ID and name when i click the combo box however only the hotel ID is visible on the form after the hotel ID is selected.

thanks
Apr 23 '09 #18
mshmyob
904 Expert 512MB
On your column width setting for the combo box set it to something like this

0;3


cheers,

@tfurubay
Apr 23 '09 #19
NeoPa
32,556 Expert Mod 16PB
You're quite right Todd (I don't get to play with form stuff much. Much of what I post I have to dig up first).

In that case, it would make sense to use the technique posted earlier (by both Mshmyob and myself). In this case though, the separate control would be a Label. The code in the AfterUpdate event of the ComboBox would have to update the .Caption property of the Label with the .Column(1) value from the ComboBox control.

Let us know if you need help setting up this code (You will need to include names of the controls you've set up for the task).
Apr 23 '09 #20
NeoPa
32,556 Expert Mod 16PB
@mshmyob
Good thinking Mshmyob. That shows the name, but at the expense of hiding the ID.
Apr 23 '09 #21
hi,

i used this but it didn't work:

me.hotel =me.combo67.column(1)

"hotel" is the control source for the field i'd like to update
"combo67" is the name of the control box.

error message is "MS Access can't find the macro "me" i know i am not "getting" something
Apr 24 '09 #22
mshmyob
904 Expert 512MB
Is HOTEL the name of your field? I thought you wanted to update a text control on your form.

You are using the combo box to choose a hotel ID and hotel name and then trying to change the hotel name in your table based on your hotel name you chose??? That does not make sense.

If you want to change a text box or label control to display the name of the hotel chosen then give the text box a name like txtHotel or a label a name like lblHotel, then change your code to (be sure you are in VBA code and not the Macro screen):

Expand|Select|Wrap|Line Numbers
  1. Me.txtHotel = Me.Combo67.Column(1)
  2.  
cheers,

@tfurubay
Apr 24 '09 #23
sorry, my terminology stinks... the form has a field named "hotel". This field is controled by the hotel field on the table. i am hoping to update the value of "hotel" with column "x" from the combo box. does this make sense.

i'm still not getting it. I even tried this do see if half of the logic worked by using this: =Hotel="test"

i'm going to plug away at this. thanks!
Apr 24 '09 #24
mshmyob
904 Expert 512MB
That is OK.

First the form does not have FIELDS - you have a control (ie: text control) that is bound to a field in your table or unbound (meaning not related to any field in any table (or queries etc.).

What I suggest is this....

1. Keep your combo box as is.
2. Create a text box that is UNBOUND and call it txtHotel on your form
3. Put the code I told you in the AFTERUPDATE event of the combo box

See if that works like you want.


By the way you cannot change a bound control like you are trying - you could use an update query but you actually don't want to update your bound control for what you are trying to accomplish.

cheers,

@tfurubay
Apr 24 '09 #25
hi Msh,

success! i had to put the code in the event procedure. didn't work in the expression builder.

and i was able to bound the hotel field to the table. everything worked. you and neo are godsends and wonderful teachers. thanks again!
Apr 24 '09 #26
NeoPa
32,556 Expert Mod 16PB
@tfurubay
Todd,

I would echo what Mshmyob said. "Don't bind the new Hotel control to the underlying recordset."

Binding causes it to be saved away into the record. We discussed this earlier and I got the impression you understood the concepts.

I would also suggest (diverging from Mshmyob here) that you use a Label control here rather than a TextBox. Assigning a value to the Caption property of a Label causes it to be displayed, but there's no fiddling around trying to configure it so that it cannot be edited other than by using the associated ComboBox control (problems you will need to consider if using a TextBox control).
Apr 24 '09 #27
mshmyob
904 Expert 512MB
@NeoPa
Diverge away. I would also use the caption property of a label for this purpose.

cheers,
Apr 24 '09 #28
hi there. in this case, i do need to save the hotel to the table. i realize it's contrary to proper relational db design but i am saving the data to a legacy table that is a flat file.

i did lock the hotel text box so ppl will not be able to edit the box. i will figure out how to use a label in place of this method, thanks!

My next challenge is to create required field logic and corresponding error messages. will post a new string for that. thanks
Apr 24 '09 #29
NeoPa
32,556 Expert Mod 16PB
In that case Todd, it will need to be a TextBox after all. You cannot bind labels to anything.

We'll look out for your new thread :)
Apr 24 '09 #30
okay. got it and thanks. i am humbled by your patience and benevolence! i wish i could express how appreciative i am of people like you and mish. a 1000 blessings to both of you!
Apr 24 '09 #31
NeoPa
32,556 Expert Mod 16PB
It's not often I'm accused of having patience :D

That gives you a bonus point Todd.

It's always nice to hear we've helped though :)
Apr 24 '09 #32
you do and you did. thanks!
Apr 24 '09 #33

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Philipp H. Mohr | last post by:
Hello, I would like to store multiple dictionaries in a file, if possible one per line. My code currently produces a new dictionary every iteration and passes it on to another peace of code. In...
2
by: Jen F. | last post by:
I have inherited a medical database in which there are multiple values stored in a single field (ie. "Current Conditions" field might contain 1-20 different conditions, separated by comma (ie....
5
by: Homer Simpson | last post by:
Hi All, I'm trying to write a method where I pass three arguments and the method returns six values. All the values will be doubles. First, is it possible to get multiple values returned by a...
0
by: g.o.atkins | last post by:
Hi, Is there anyway to store multiple values in the System.Net.Cookie object?? I cannot use the System.Web.HttpCookie object (which allows for multiple values) as I am trying to set the...
1
by: sheenaa | last post by:
Hello friends, I m using ASP.NET with C# 2005 and SQL SERVER 2005 for the ASP.Net Website. I m using sqldatasource to connect and retrieve the data from database and then it displays the data...
1
by: wendy184 | last post by:
I'm used to using 2007 which allows multiple values in the lookup wizard, this helps hugely with my queries as the database i'm building has information on one parent who may have up to 5 kids. ...
0
by: NothingMore | last post by:
I am using VB .NET and I am stumped as I draw blanks and cant find anything about adding multiple values to a combo box item. Without using external files. Example: (hope this helps a bit) ...
2
by: MicaK | last post by:
Good Morning, I am new to this forum, and extremely new to VBA, so there may be a very simple explanation to this. I also apologize if I am giving you and excessive amount of detail. I have a...
1
by: sarankarthik | last post by:
Hi, I have some array of values,say for example Attribute1 contains 1,2,3,4,5,6,7 values.. Please tell me how can i store multiple values in an xml file for a single variable. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.