combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to have it where when i select a a value in one combo box it will only
allow certain values in another combo box next to it to be selected. Now i am
not too sure how to approach this so any help would be wonderful.
 
Hi, Alfred.

This is done by setting the RowSource property of the second combo box in
the AfterUpdate event procedure of the first. Then requery the 2nd CB.

Me!MySecondComboBox.RowSource = "SELECT <fieldlist> FROM <table> WHERE
<field> =" & Me!MyFirstComboBox
Me!MySecondComboBox.Requery

Sprinks
 
Sprinks,

Thanks for the speedy reply. What i have tried to do is use the code you
provided for me and use it in the after update of my "second combo box". But
after i inset the code it part of the code becomes red and it says that their
is a compile error, expected expression. The part that lights up in red is
----- where <organization> =" & Me!assigned_location"----- Do you have any
idea what i did wrong
 
Alfred,

What you're trying to do is reassign the RowSource of the 2nd combo box once
the user has made a selection from the 1st, so the code should be in the
AfterUpdate event of the first box NOT the 2nd as you describe.

Also, the RowSource needs to evaluate to a valid string, so there should be
quotes around everything up to the reference to the combo box value, which is
then concatenated with the value. Your posted code has an extra quote after
Me!assigned_location.

Hope that helps.
Sprinks
 
One other thing, Alfred. I hope I didn't confuse you--the <> symbols I used
in my post were meant to describe something you need to fill in, they are not
part of a valid string. If Organization is the name of the field matching
the selection of the first combo box, your code will be something like:

Me!YourSecondComboBox.RowSource = "SELECT Field1, Field2 FROM YourTable
WHERE [Organization] = " & Me!assigned_location

Sprinks
 
Does it matter if i have 2 tables or 1 table with the code that you gave me?


Sprinks said:
One other thing, Alfred. I hope I didn't confuse you--the <> symbols I used
in my post were meant to describe something you need to fill in, they are not
part of a valid string. If Organization is the name of the field matching
the selection of the first combo box, your code will be something like:

Me!YourSecondComboBox.RowSource = "SELECT Field1, Field2 FROM YourTable
WHERE [Organization] = " & Me!assigned_location

Sprinks

Alfred FPC said:
Sprinks,

Thanks for the speedy reply. What i have tried to do is use the code you
provided for me and use it in the after update of my "second combo box". But
after i inset the code it part of the code becomes red and it says that their
is a compile error, expected expression. The part that lights up in red is
----- where <organization> =" & Me!assigned_location"----- Do you have any
idea what i did wrong
 
If you mean that the rows of your combo box are coming from more than one
table, no, the code will work as long as the expression evaluates to a valid
SQL string, for example:

Me!MySecondComboBox.RowSource = "SELECT Orders.OrderNumber,
Orders.OrderComplete, Customers.CustomerName
FROM Customers INNER JOIN Orders ON Customers.CustomerID =
Orders.CustomerNumber WHERE [Customers].[CustomerID] = " &
Me!assigned_location

If your SQL is weak, set up a query in Query Design View, and choose View,
SQL to cut and paste the SQL version. Then add your WHERE clause.

Hope that helps.
Sprinks


Alfred FPC said:
Does it matter if i have 2 tables or 1 table with the code that you gave me?


Sprinks said:
One other thing, Alfred. I hope I didn't confuse you--the <> symbols I used
in my post were meant to describe something you need to fill in, they are not
part of a valid string. If Organization is the name of the field matching
the selection of the first combo box, your code will be something like:

Me!YourSecondComboBox.RowSource = "SELECT Field1, Field2 FROM YourTable
WHERE [Organization] = " & Me!assigned_location

Sprinks

Alfred FPC said:
Sprinks,

Thanks for the speedy reply. What i have tried to do is use the code you
provided for me and use it in the after update of my "second combo box". But
after i inset the code it part of the code becomes red and it says that their
is a compile error, expected expression. The part that lights up in red is
----- where <organization> =" & Me!assigned_location"----- Do you have any
idea what i did wrong

:

Hi, Alfred.

This is done by setting the RowSource property of the second combo box in
the AfterUpdate event procedure of the first. Then requery the 2nd CB.

Me!MySecondComboBox.RowSource = "SELECT <fieldlist> FROM <table> WHERE
<field> =" & Me!MyFirstComboBox
Me!MySecondComboBox.Requery

Sprinks

:

I want to have it where when i select a a value in one combo box it will only
allow certain values in another combo box next to it to be selected. Now i am
not too sure how to approach this so any help would be wonderful.
 
Back
Top