By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

List Box / Combo Box Selection

P: 29
I have a combo box "A" on a form that selects choices from a row source query. this row source query is simply a table of two colomns. the first colomn is an acronym (AASC) for the description "academic counseling".

Question:
How do I create a list box to simply display the second column of this query for which the combo box choice has been selected?

shiznaw
Jun 9 '07 #1
Share this Question
Share on Google+
6 Replies


P: 7
set the rowsource for the list box in the click event of the combo box. eg
Expand|Select|Wrap|Line Numbers
  1. Private Sub combo1_Click()
  2.  list1.rowsource = "select * from (whatever) where (code) = '" & combo1.text & "'"
  3. end sub
all those inverted commas at the end assume that you are comparing with a text code. If the code is numeric (phew) just omit them
Jun 9 '07 #2

P: 4
Hi Shiznaw

it sounds like what you want to do simaller to cascading combo boxes.

See if this document from microsoft will help you Basing one combo box on another I've used it for "combo to combo" and combo to list"

I have a combo box "A" on a form that selects choices from a row source query. this row source query is simply a table of two colomns. the first colomn is an acronym (AASC) for the description "academic counseling".

Question:
How do I create a list box to simply display the second column of this query for which the combo box choice has been selected?

shiznaw
Jun 9 '07 #3

P: 29
set the rowsource for the list box in the click event of the combo box. eg
Expand|Select|Wrap|Line Numbers
  1. Private Sub combo1_Click()
  2.  list1.rowsource = "select * from (whatever) where (code) = '" & combo1.text & "'"
  3. end sub
all those inverted commas at the end assume that you are comparing with a text code. If the code is numeric (phew) just omit them
okay, so I appreciate what you have given, but I don't like using stuff,
if I can't understand it. Can you explain what the following does?

= '" & combo1.text & "'" <~~~ why are you taking an object from the form
and encompasing it within quotes? Thanxs in advance, Mr. Guru.

Shiznaw, new kid.
Jun 10 '07 #4

NeoPa
Expert Mod 15k+
P: 31,494
okay, so I appreciate what you have given, but I don't like using stuff,
if I can't understand it. Can you explain what the following does?

= '" & combo1.text & "'" <~~~ why are you taking an object from the form and encompasing it within quotes? Thanxs in advance, Mr. Guru.

Shiznaw, new kid.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_Click()
  2.  List1.RowSource = "SELECT * FROM [Table] WHERE [Field]='" & Combo1 & "'"
  3. End Sub
The string that the RowSource is set to should be something like :
SELECT * FROM [Table] WHERE [Field]='Robert Molson'
Assuming that the contents of Combo1 is "Robert Molson".
The code firstly creates the string as above and assigns it to the RowSource of List1. The quotes (') are to tell the SQL interpreter (that deals with the SQL string), that the enclosed data is a string literal rather than another type (numeric; date; etc).
Jun 11 '07 #5

P: 29
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_Click()
  2.  List1.RowSource = "SELECT * FROM [Table] WHERE [Field]='" & Combo1 & "'"
  3. End Sub
The string that the RowSource is set to should be something like :

Assuming that the contents of Combo1 is "Robert Molson".
The code firstly creates the string as above and assigns it to the RowSource of List1. The quotes (') are to tell the SQL interpreter (that deals with the SQL string), that the enclosed data is a string literal rather than another type (numeric; date; etc).
the following worked:

Expand|Select|Wrap|Line Numbers
  1. 'to control the source of the CESA Code Field
  2.     Me.cCode.RowSource = "SELECT [cesacodes] FROM [CESA codes] WHERE [description]='" & cdescript & "' "
  3.     cCode.Requery
I want to thank you MS / VB Gurus for helping me. I promise to return the favor by contributing how ever I can to others who may know less than I...but I doubt I know ne thing.

Thank YOU !!!!
Jun 11 '07 #6

NeoPa
Expert Mod 15k+
P: 31,494
Not a problem. Glad to help out.
As you get better, there will be more who come here that you can help.
Jun 11 '07 #7

Post your reply

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