MonkeyPie
asked on
Access VBA - populate combo box with ABC etc up to variable count
Access form : I need a form combo-box drop down with values A, B, C, D etc up to count of records in a recordset.
Recordset is Groups in company, so if there are 8 groups, I need drop-down to have A through H as options, but if only 4 groups, then A through D in drop-down.
Can't quite get my head around this. Can anyone help? Thank you.
Recordset is Groups in company, so if there are 8 groups, I need drop-down to have A through H as options, but if only 4 groups, then A through D in drop-down.
Can't quite get my head around this. Can anyone help? Thank you.
BTW, it would be easier with a table of numbers from 1-26, but I just like my multi-functional tbl_Numbers and the numerous ways I find to use it. ;-)
You could also use DCOUNT to get the number of rows, and a procedure with a case statement to set the value list of the rowsourcetype in the combo box - not nearly as elegant as fyeds,
ASKER
Thanks so far.
Based on your responses, I would like to take it one step further:
Select chr(64 + IntNumber) as letter From GROUP
where intNumber is an auto-increment 1, 2, 3 etc. I know I have done something like this before, but I can't remember or find it.
There is some special trick to add an increment column to SQL - does anyone know how?
Based on your responses, I would like to take it one step further:
Select chr(64 + IntNumber) as letter From GROUP
where intNumber is an auto-increment 1, 2, 3 etc. I know I have done something like this before, but I can't remember or find it.
There is some special trick to add an increment column to SQL - does anyone know how?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have a table (tbl_Numbers) I use for a variety of things. The table contains a single field (intNumber) and ten records (the values 0 to 9). With this table, you could create a query that provides you the numbers 1 - 26
Select tens.intNumber * 10 + Ones.intNumber as intNumber
FROM tbl_Numbers Tens, tbl_Numbers Ones
WHERE tens.intNumber * 10 + Ones.intNumber BETWEEN 1 and 26
From there, you could make that a subquery and use whatever your # of Groups is to get your list.
SELECT chr(64 + intNumber) as GroupLetter
FROM (
Select tens.intNumber * 10 + Ones.intNumber as intNumber
FROM tbl_Numbers Tens, tbl_Numbers Ones
WHERE tens.intNumber * 10 + Ones.intNumber BETWEEN 1 and 26
) as subNumbers
WHERE subNumbers.intNumber <= GroupNumber
ORDER BY subNumbers.intNumber