473,396 Members | 2,081 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,396 software developers and data experts.

Combo Box value depends on another Combo Box

I'm new to this site, so forgive me if this is the wrong forum.

My problem is as follows:
I have a form based on a Person table (usual identifying fields - name, address, etc) with all fields from the table at the top of the form.

At the bottom of the form, I need 2 pieces of info from another record in the Person table - ID (the key) and FullName.
I want the User to be able to select the FullName so I can tie the 2 records together in a Spouse table.
I have tried to use a combo box with all persons' names and a corresponding combo box that derives the key from the previous combo box with a
Expand|Select|Wrap|Line Numbers
  1. SELECT [OtherID] FROM [OtherPersonQuery] WHERE Other = [Combo31]; 
statement in the Row Source for Combo36 (the Other ID field).

This works a little, but leaves me with 2 problems:
- First, the combo box doesn't fill with any value even though the value is available in the drop-down portion (it is unique, so there is only one value).
- The second problem is that I can't make it update corresponding to changes in the Combo31 box (eg if Combo31 changes from Fred to Wilma, the Other ID field should change from 303 to 909.

Is there some way to make the second combo box mime the first one, or am I approaching this the wrong way? Any help would be appreciated.

I hope my explanation is clear.
Jul 29 '13 #1
7 9550
jimatqsi
1,271 Expert 1GB
If changing the first combo box should change the second combo box, put some code into the OnChange event of the first combo box.
Expand|Select|Wrap|Line Numbers
  1. if me.dirty then me.dirty = false
  2. me.combobox2.requery
The reference to me.dirty makes sure any changes on the screen are recorded before trying to execute the requery.

Jim
Jul 29 '13 #2
I did a requery in the OnChange of the first combo box and that part works fine. Thanks. I still don't know how to force the value into the combo box without actually selecting it from the drop-down. I'd like to do that so I can hide the field from the User since its presence on the form is confusing. Is there some way to do that? I can't find any. I'd be happy with a text box but that doesn't allow a query, as far as I can discern.
Jul 30 '13 #3
jimatqsi
1,271 Expert 1GB
You're saying you want to actually choose a value for the second combobox? Not change the list of available values but select a value? In the AfterUpdate event of the first combo box (not OnChange as I mistakenly said previously) you can add
Expand|Select|Wrap|Line Numbers
  1. me.combobox2="xyz"
. Or you can loop through the items in the combo box until you find the one you want like this
Expand|Select|Wrap|Line Numbers
  1. dim intItem as integer
  2. for intItem = 0 to ComboBox2.ListCount-1
  3.    if ComboBox2.column(intItem)=me.Combobox1 then
  4. me.combobox2(intItem).Selected=true
  5. endif
  6.  
  7. next
  8.  
Note that if your combobox has more than one column, then (intItem) must be changed to (0,intItem) to reference the first column

Jim
Jul 30 '13 #4
zmbd
5,501 Expert Mod 4TB
First, So long as you are using Access and/or VBA this is the place to be, and welcome!

{edit}
Second, check which column is bound in the combo boxes. This will tell you which of the following to use:

Third,
Expand|Select|Wrap|Line Numbers
  1. SELECT [OtherID] FROM [OtherPersonQuery] WHERE Other = [Combo31];
is malformed.
Change this to either:
if the returned value in [Combo1] is numeric
Expand|Select|Wrap|Line Numbers
  1. SELECT [OtherID] FROM [OtherPersonQuery] WHERE "Other = " & me.[Combo1];
if the returned value in [Combo1] is text string
Expand|Select|Wrap|Line Numbers
  1. SELECT [OtherID] FROM [OtherPersonQuery] WHERE "Other = '" & me.[Combo1] & "'";

fourth, we need the code you are using in the after_update event in the combo boxes that you are using to update the spouses table with.
Jul 30 '13 #5
zmbd
5,501 Expert Mod 4TB
jimatqsi:
Bound controls are much easier to work with than what you propose.
Jul 30 '13 #6
First of all, thanks to all the responders for looking at my problem. As it turns out, I was making a much bigger problem out of it than needed to be. I had simply forgotten that you could access multiple columns out of a combo box query and that is what my second field ultimately needed.

When it finally came to me, I had other issues with quoting that masked the problem even further until I finally figured it all out.

If anyone cares to know what I ultimately had to do, it was to put:
Expand|Select|Wrap|Line Numbers
  1. sqlStr = "INSERT into Spouse(PersonID, SpouseID, SpouseName) VALUES ([ID], Combo31.Value, " + Combo31.Column(1) + ");" 
as well as:
Expand|Select|Wrap|Line Numbers
  1. sqlStr = "INSERT into Spouse(PersonID, SpouseID, SpouseName) VALUES (Combo31.Value, [ID], FullName);" 
before executing each sql statement.

The final piece that caused me to wonder what was happening was being able to place the "Combo31.Value" piece inside the quotes and have it execute perfectly, but I had to place the "Combo31.Column(1)" piece outside the quotes or I received a 3805 error telling me the function Combo31.Column() was undefined. I still don't understand why the 2 pieces of sql have different quoting requirements, but at least it works well now.

I feel kind of stupid for soliciting the help when the answer turned out to be so obvious, but it was a couple of different questions and answers on this site (including my own) that caused me to see the solution, so I appreciate the help.
Aug 7 '13 #7
jimatqsi
1,271 Expert 1GB
No need to feel stupid about asking for help. We've all been there. :)
Aug 7 '13 #8

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

Similar topics

2
by: D | last post by:
Book inventory. Access 2K. I'm trying to let a user choose a book title from one combo box, then a book number for that book title from another combo box. I can filter the book number combo with...
1
by: damatoer | last post by:
I am having problems with attempting to filter a form based on criteria selected in a combo box from another form. I am attempting to have a user select a order number from a combo box that is...
1
by: meganrobertson22 | last post by:
Hi Everyone- I am trying to use a simple macro to set the value of a combo box on a form, and I can't get it to work. I have a macro with 2 actions: OpenForm and SetValue. I can open my form,...
7
by: sara | last post by:
I have a form where the user selects an item from a list box, and then works on that item. The user chooses an AD, then opens a form to assign departments to the ad. The top of the Depts form has...
0
by: CalMyPal | last post by:
Basing one combo box on another January 31, 2005 By Sal Ricciardi Making choices is what a combo box is for, but sometimes one choice depends on another. In this installment, you'll learn how to...
2
by: SM | last post by:
Hello, I have an HTML file that contains a form with 2 selection list (combo box). The first combobox 'onchange' function, addColor(),adds a new color to the second combobox. I have half of the...
6
by: troy_lee | last post by:
I have a continuous form that has one combo box (cbo1) with the selectable values of "Removal" and "Installation". I would like to change another combo box (cbo2) value list based on the selection...
1
by: sejal17 | last post by:
Hello Please can anyone help me on my this question?I want to load country combobox and after selecting one country i want to load state combo of that country.I have done it successfully but...
3
by: lrw0831 | last post by:
I have a table named AssignedTo. In this table are the fields: AssignedTo_ID, Department, Employee. On my form, I need to create 2 combo boxes. The first one will select the department. Based...
1
by: ncsthbell | last post by:
Hello, I hope I can do a good enough job trying to explain this situation! I have inherited the maintenance for an access database and I have been requested to make a change to a form to add 2...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.