473,888 Members | 1,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create Access Drop Combo Box to display one table field but save an associated field

6 New Member
I have two tables;

1. Called "Courses" that contains two fields "Course ID" and "Course Name".

2. Called "Sessions" that contains a field called "Course ID".

Then I have a form with a combo box that uses the "Course_Nam e" field for its list and stores the item you select from that list into the "Course ID" field on the "Sessions" table.

What I want it to do is use the "Course_Nam e" as its drop down list but store the associated "Course ID" from that table into the "Course ID" field into Sessions table.

For Example:

I select MS Access from the drop down list

Course_Name = MS Access
Course_ID = 1

If I select "MS Access" from the drop down list I want it to store "1" instead of "MS Access" into the "CourseiD" field in Sessions table.

By the way Sessions table the field CourseID is set to number.

Is this possible?
Aug 7 '08 #1
8 24809
hjozinovic
167 New Member
Hi Gurmet!
Yes this is very possible and quite easy too.
Step 1:
In properties of combo control cboCourse put:
Row Source Type: Table/Query
Row Source: Query containing CourseName and CourseID in this order!!!
Column Count: 2
Column Widths: 3cm;0cm (make sure the second value is zero!!! This way second column will be present but will not be displayed when you open the drop-down list)
Step 2:
Now let's go to coding :-) In After Update event of the same combo control you should write code like this:
Expand|Select|Wrap|Line Numbers
  1. Me!SessionCourseID = Me!cboCourse.Column(1)
Note that Column(0) is reffering to first column in drop-down list (CourseName) and Column(1) is reffering to the second column (CourseID) whose width is set to zero!

This code is correct if the control SessionCourseID is on the same form like combo box control, and if its source property is set to CourseID in table Session.

regards, H.
Aug 7 '08 #2
NeoPa
32,584 Recognized Expert Moderator MVP
Nice answer H :)

You may want to take it a step further though. It's possible to bind the ComboBox control to the field itself in the form. This automatically ties the value in to the underlying table field.

Benefits are :
  • No code required.
  • When editing existing records the value shown automatically shows the related line in the ComboBox.
Aug 7 '08 #3
hjozinovic
167 New Member
Hi.
Thanks. I was thinking the same, but he wanted to store the value in a different table:
What I want it to do is use the "Course_Nam e" as its drop down list but store the associated "Course ID" from that table into the "Course ID" field into Sessions table.
With my solution control source property of control CourseID is tied to Sessions.Course ID and is automatically populated with values from Combo box.

H.
Aug 7 '08 #4
NeoPa
32,584 Recognized Expert Moderator MVP
Good answer H, but I think the "other" table in this instance was [Sessions]. IE It was NOT the table populating the ComboBox ([Courses]). However, it is, unless I've misunderstood the original post, the table the main form is built upon.

Anyway, both solutions are now available to any reader (with explanations of which to use in which circumstances), so that's a bonus :D
Aug 7 '08 #5
gurmet
6 New Member
Hi H, NeoPa

I did what you suggested.
I m able to view my drop down with the values, which mean just display the course code, the course id did not appear.
Upon my selection of course code from the dropdown, i get this error message:

The value you entered isn't valid for this field.
For example, you may entered text in a numeric field or a number that is larger than then FieldSize setting permits.


My table (Sessions) the field is course_id as numeric because i only want to keep the course_id not the course code, because a users can edit the course code but not the course_id and also due to data redundancy.

Pls help.
Gurmet
Aug 8 '08 #6
gurmet
6 New Member
Hi Guyz...while waiting ...try to figure it out from your explanation step by step again, and i did was to change the code below becuase my couse_id is first column, course_code was second column,

Me!course_id = Me!course_id.Co lumn(0)
and now it works.

Thank you very much.
Regards.Gurmet
Aug 8 '08 #7
hjozinovic
167 New Member
That's great Gurmet!
Obviously you understand it better now and you're able to solve minor problems yourself. That's great!
Welcome to bytes ;-)
Aug 8 '08 #8
NeoPa
32,584 Recognized Expert Moderator MVP
...
I did what you suggested.
I m able to view my drop down with the values, which mean just display the course code, the course id did not appear.
Upon my selection of course code from the dropdown, i get this error message:
...
If you want to use this technique then you will need to make the .BoundColumn of the ComboBox match the column that matches the field that you want it bound to.

From your post #7 I would guess that would be 0, but I don't have the info to say for sure I'm afraid.

Anyway, you have the other way working, so don't worry about this unless you particularly want to do it this way.

Well done, BTW, it's always gratifying to see members getting solutions for themselves after learning a little about what's available :)
Aug 8 '08 #9

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

Similar topics

30
3158
by: Andante.in.Blue | last post by:
I just browsed through some of my Access links when I came across the Ten Commandments of Access (http://www.mvps.org/access/tencommandments.htm). Some of the points I heartily agree with (and wish that my predecessor had followed) but -- alas -- being a relative beginner to Access, I can't see the reasoning behind one of the points and the site does not provide any rationale / explanation for its presence either: 2. Thou shalt never...
10
2590
by: Bob Darlington | last post by:
I am using the following SQL as a RowSource for a combo box on a form. "SELECT LAN, TenantName as , ShopNum as FROM qTenantSelect " The field 'ShopNum' is a text field and has a caption property set to 'Shop Number' in the table design. In the combo box though, I want to use 'Shop' as the heading (to save width) as shown in the SQL above. But the combo shows 'Shop Number' as a heading in form view.
6
2488
by: skgolden | last post by:
My husband and I own a small temporary labor company and deal with 4 major clients (A,B,C & D), each of which has about 2 dozen units in our tristate area that we deal with (ie, Company A, units a,b,c,d,e etc). We send temps possessing various skills (cashier, cook, hostess, etc) to the individual units as needed. What I'm trying to do is create a schedule we can use each day, for example: Monday, June 1, 2004 Company A, unit e Alice...
3
6098
by: krygsma | last post by:
So, I need to figure out how to do what I want to do with Access. I have many questions with mutually exclusive options, each option has a value, never=0, few times=1...ect.. (then when questions are "reversed", never will equal 4, which can be handled later but I'm open to any ideas) but need to be displayed as text. The easiest solution to this, I thought, would be option groups, perfect, they look beautiful, it seems quite logical that...
9
6776
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the second combo to change depending on what values the user selects in the first box, it's just that every time the user changes the first combobox, the second combobox FOR EVERY RECORD goes blank.
3
8248
by: rlm | last post by:
This small problem to solve involves a two table database (one parent and one child table), one winform and two combo boxes. Combo box A is populated in the Load event. Combo box A pulls data from the parent table. A second combo box (box B) will be populated (from the child table) based on data selected in by the user in combo box A. In the datastore the child contains a numeric foreign key from the parent.
27
3812
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB updates the same data in all other four tables in the right places. I know it would be possible by using the ForeignKeyConstraint object. I have created the tables using the DataSet Visual Tool and I know it doesn't create any ForeignKeyConstraint obj....
1
1429
by: Bob | last post by:
Hi all, I've designed a database that has an events table and an application table. Each event has an application associated with it and I've stored an application code in the events table then stored the actual name in the associated application table. My problem is that on a form I want to display all the information from the events table, but also a drop down of the name of the application, not the code (which is stored in the...
12
3295
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it won't allow any fields to have data entered into them. I can edit & save existing records without problem. When I go into the Tables view, I can add records and data ok and save without problem. I go back into the Table and I can see the data. ...
0
9961
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11182
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10886
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9597
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5824
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.