Combo Box Depending on Combo Box

X

XMan

I know this one has been asked a million times but I need an example for the
trick.
ComboBox2 query depends on ComboBox1 selected value.
ComboBox1 is Customer Class: A, B, C
ComboBox2 is Customer Name. These belong to selected Class.

TIA.
 
G

Graham Mandeno

Hi XMan

Either:
1) Set the ComboBox2's RowSource to:
Select CustID, CustName from CustTable where CustClass=Forms![Your
Form]![ComboBox1]

....and in ComboBox1_AfterUpdate say:
ComboBox2.Requery

or:
2) In ComboBox2_AfterUpdate say:
If IsNull(ComboBox1) then
ComboBox2.RowSource = ""
Else
ComboBox2.RowSource = "Select CustID, CustName from " _
& "CustTable where CustClass='" & ComboBox1 & "'"
End If

In either case, add the following to Form_Current:
Call ComboBox2_AfterUpdate

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
 
X

XMan

It's very good. Thanks for your help.

Graham Mandeno said:
Hi XMan

Either:
1) Set the ComboBox2's RowSource to:
Select CustID, CustName from CustTable where CustClass=Forms![Your
Form]![ComboBox1]

...and in ComboBox1_AfterUpdate say:
ComboBox2.Requery

or:
2) In ComboBox2_AfterUpdate say:
If IsNull(ComboBox1) then
ComboBox2.RowSource = ""
Else
ComboBox2.RowSource = "Select CustID, CustName from " _
& "CustTable where CustClass='" & ComboBox1 & "'"
End If

In either case, add the following to Form_Current:
Call ComboBox2_AfterUpdate

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.

XMan said:
I know this one has been asked a million times but I need an example for the
trick.
ComboBox2 query depends on ComboBox1 selected value.
ComboBox1 is Customer Class: A, B, C
ComboBox2 is Customer Name. These belong to selected Class.

TIA.
 
A

Adrian Jansen

I know you have already been helped on this, but its worth pointing out that
for a question that you know has been asked 'a million times', you can
search the Google archive for related queries.

http://groups.google.com/groups?hl=en&lr=&q=&btnG=Google+Search&meta=group%3
Dmicrosoft.public.access.formscoding

Will allow searching just this newsgroup. Others are possible, of course.
It a great resource.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top