473,322 Members | 1,232 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,322 software developers and data experts.

How to with a combo box

When clicking an item from a drop down list on a combo box, how does one
make another combo box make a selection from it's own list? No matter what
event I use for my code in the first combo box, seems to always generate an
error when I try and refer to the other combo box.

I'm aware of the necessity of setting the focus on the second box before
referring to it, unless one is using the default value. I'm too tired to
type out everything I've been playing around with (I've been at it for a
while now) and no matter what I always get some sort of error or unwanted
results. I'm hoping this is not something unusual and that someone can
simply show me a generic example of what might work.

Thanks,

Gord
Sep 3 '08 #1
4 2763
Gord wrote:
When clicking an item from a drop down list on a combo box, how does
one make another combo box make a selection from it's own list? No
matter what event I use for my code in the first combo box, seems to
always generate an error when I try and refer to the other combo box.

I'm aware of the necessity of setting the focus on the second box
before referring to it, unless one is using the default value.
Actually that is incorrect. You only need to set focus to use the Text
property and that is almost never the one you want. You want the Value
property which can be set without first setting focus.
I'm
too tired to type out everything I've been playing around with (I've
been at it for a while now) and no matter what I always get some sort
of error or unwanted results. I'm hoping this is not something
unusual and that someone can simply show me a generic example of what
might work.
All it should take is...

Me.ComboBoxName = SomeValue

Is it a multi-column ComboBox? That can change things since you might need
to set the value to one found in a column that is not the one you see.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Sep 3 '08 #2
Typically the first combobox has the value of the primary key in some table.
We'll call it CustomerID in TblCustomer. Then the second combobox has the
value of the related foreign key in another table. We'll call it CustomerID
in TblOrder. So in the first combobox you choose a customer and in the
second combobox you choose from a list of orders by that customer. The
rowsource of the first combobox is a query based on TblCustomer. CustomerID
is the first column in the query and the Bound Column property of the
combobox is 1. The combobox is named CustomerID. The rowsource of the second
combobox is a query based on TblOrder. OrderID is the first column in the
query, CustomerID is the second column in the query and the Bound Column
property of the combobox is 1. The combobox is named OrderID. The criteria
for CustomerID is Forms!NameOfYourForm!CustomerID.

Put the following code in the AfterUpdate event of the first combobox:
Me!OrderID.Requery
Me!OrderID.SetFocus
Me!OrderID.DropDown

When you select a customer in the first combobox, the second combobox will
dropdown and only display
orders by the customer you selected. Focus will be on the second combobox.

Steve

"Gord" <x1******@telus.netwrote in message
news:FKnvk.11601$nu6.3003@edtnps83...
When clicking an item from a drop down list on a combo box, how does one
make another combo box make a selection from it's own list? No matter
what event I use for my code in the first combo box, seems to always
generate an error when I try and refer to the other combo box.

I'm aware of the necessity of setting the focus on the second box before
referring to it, unless one is using the default value. I'm too tired to
type out everything I've been playing around with (I've been at it for a
while now) and no matter what I always get some sort of error or unwanted
results. I'm hoping this is not something unusual and that someone can
simply show me a generic example of what might work.

Thanks,

Gord

Sep 3 '08 #3
I just figured it out.

I can click one combo box and set the other combo's value by applying the
appropriate column value from the combo just clicked. This may set the
listindex of the second combo to an incorrect record but by setting up a
public boolean I can determine which combo was clicked. I'll use the
listindex from that combo to verify the record I want.

Thanks for your efforts.

Gord
Sep 4 '08 #4
Gord wrote:
....
Maybe I misunderstand, but I'm not finding to be true what you say
about a combo box selecting the first value in its bound column that
has duplicates "even if you make the selection manually". When I
drop the box and click on a selection I'm finding that the listindex
property sets to the row I clicked on and not on the first one with a
matching value in its bound column. ...
Just tested in Access 97 and 2003. Given a Combo with columns...

John Doe 1
Jane Doe 2
Tom Doe 3
Harry Doe 4

....with the bound column being the second one, The Combo displays "John" no
matter which row I select from the drop-down. That is what I was describing
in case it wasn't clear.

You are correct that if I display the ListIndex property in a MsgBox in the
AfterUpdate event it will reflect the index of the row I selected, but if I
check the ListIndex again (after AfterUpdate has completed), it always
reflects the ListIndex value of the first row in the list with the bound
value I picked. In the example above that value is zero.
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Sep 5 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mark | last post by:
I've been working on an Access 2000 database for a couple of weeks now. I took a course in access about a year ago, a crash course, and I learned a ton, but I didn't touch Access for the year since...
2
by: misschristalee | last post by:
I'm having a brain blockage day.... Scenario: Search Form with 6 text boxes Query has same six fields Each has this IIF: IIf(IsNull(!!),"",!!) with each dictating the correct text box of...
2
by: Wayne | last post by:
I've implemented the following successfully on a single form before, but the continuous form is giving me problems. I have 2 combo boxes, Combo 1 and Combo 2. The values in Combo 2 are dependent...
8
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
4
by: John Tyce | last post by:
The problem that I am now having, involves refreshing controls. I have allot of text boxes, several combo boxes and grids. These controls are showing live data from an Oracle database. I have dates...
3
by: hmiller | last post by:
Hey everyone, I am having a hell of a time trying to set this menu system up. Here's what I'm trying to do. Combo Box One; is populated by names under properties "row source" "Phase 1"...
2
by: kiranmn75 | last post by:
I want to dynamically populate a combo box through javascript. Data is coming from a array. Sometimes data list may contain items in excess of 2000. Explorer takes more than 5 seconds to...
0
by: Jeremy Wallace | last post by:
Folks, Here's a write-up I did for our developer wiki. I don't know if the whole rest of the world has already figured out how to do this, but I hadn't ever seen it implemented, and had spent a...
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.