Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Combo Box

Status
Not open for further replies.

melvt69

Programmer
Jan 22, 2003
13
ZA
I'm busy with a VBA application in Excel. I have a combobox on a form that where I have a to display a list of codes that comes from 2 tables in a database. I load the lists seperately into the combo box, but how do i sort it afterwards? I can't seem to find something that says: ComboBox1.Sort ascending...

 
Would it not be easier to sort the tables 1st ???
You can set the sort order for a table within Access - then you only need to do it once and you don't need to change any code Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
well, the tables are sorted. Let me try an example for you to understand:

table 1: koos, john, piet.
table 2: candy, mel.

now i load table 1 in the combo and then table 2 in the SAME combo. I end up with:

koos
john
piet
candy
mel

What i want is:

candy
john
koos
mel
piet.
 
Well, there is no sort option for a combo box
What kind of database are you pulling your data from ??
Can you not just make a simple query to create a new table which is the 2 tables combined and sort that ??

Other than that, you'd be into code to read recorsets or some complex looping through an array of strings.. Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
It's a SQL database. I link it in Access to create queries, etc.
U c, it's 2 different fields. I have normal codes and then a group which these codes belong too.
Eg.
table 1: john, adrian, mel.
table 2: male, female. (Groups)
I have to have them all in one combo box.
 
As I mentioned above - why can you not create a new make table query in Access to combine those 2 tables into 1
Sort that table and use that to populate your combo box Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
okay, I've tried it and i end up with:

john adrian mel
male female

adrian - male
john - male
mel - female

how am i going to get it in the list as:

adrian
female
john
male
mel?




 
Sorry I don't understand - in your 1st example you had:
table 1: koos, john, piet.
table 2: candy, mel.

now you are saying it is:
table 1: john, adrian, mel.
table 2: male, female.

1st you wanted
candy
john
koos
mel
piet.

Now you want
adrian
female
john
male
mel

I am confused ?!?
How does the male / female indicator fit into an alphabetised list of names ??
Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
in the 1st one i forgot to mention that there's normal codes and then group codes to which the normal codes belong to.. that's where the second example comes in.
 
But where do the codes come into it if you just want a list of all names held in the 2 tables ??
Surely, you just need to do a MT query to get all names from 1st table on their own and then an append query to add the names from the 2nd table ?? Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
Thank you for all your help!
What I've done is to have 2 combo's on the form.

thx.
mel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top