If you take that query statement and replace
IntegerTable with the name of your table and
IntegerField with the name of your field
you can then execute the query.
It will ask you for the Maximum number. Input 99999
Assuming that you have at least the number 1 to 10 in your table already.
What is does is alias the integer table 5 times (so you are working with
a total of 6 copies of the table. It takes the numbers 1 to 10 in the
first copy and adds them to the numbers 0 to 9 * 10 for the second copy
and adds them to the numbers 0 to 9 * 100 in the third column, etc.
So it generates all the numbers from 1 to 9999999 then limits the
records returned to those that are between the maximum already in the
table and the cut-off number you have input.
Finally it inserts any records that meet the criteria into the table.
PARAMETERS [Increase Max # to:] Long;
INSERT INTO IntegerTable ( IntegerField )
SELECT
[IntegerTable].[integerField]+(([I_10].[IntegerField]-1)*10)+(([I_100].[integerField]-1)*100)+
(([I_1000].[IntegerField]-1)*1000)+(([I_10000].[Integerfield]-1)*10000)+(([I_100000].[IntegerField]-1)*100000)
AS NewNumber
FROM IntegerTable, IntegerTable AS I_10, IntegerTable AS I_100,
IntegerTable
AS I_1000, IntegerTable AS I_10000, IntegerTable AS I_100000
WHERE
[IntegerTable].[integerField]+(([I_10].[IntegerField]-1)*10)+(([I_100].[integerField]-1)*100)
+(([I_1000].[IntegerField]-1)*1000)+(([I_10000].[Integerfield]-1)*10000)
+(([I_100000].[IntegerField]-1)*100000)>
(Select Max(IntegerField) FROM IntegerTable) And
[IntegerTable].[integerField]+(([I_10].[IntegerField]-1)*10)+(([I_100].[integerField]-1)*100)
+(([I_1000].[IntegerField]-1)*1000)+(([I_10000].[Integerfield]-1)*10000)+
(([I_100000].[IntegerField]-1)*100000)<=[Increase Max # to:] AND
((IntegerTable.IntegerField)<11) AND ((I_10.IntegerField)<11)
AND ((I_100.IntegerField)<11) AND ((I_1000.IntegerField)<11) AND
((I_10000.IntegerField)<11) AND ((I_100000.IntegerField)<11);
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
Thanks for the reply John. However, english please (LOL), I'm just past
being a rookie.
After the "Select", you're multiplying that value by 10 and subtracting 1,
repeatedly until you max that value out but keeping it less than 100K.
(Table should only go up to 99999).
I don't understand the multiple tables after "AS".
I don't understand the values being computed in the where clause.
I'm sorry, the logic here is just way over my head. Can you simplify the
explaination?
Rich
John Spencer said:
If you have the numbers 1 to 10 in the table you can use a query like the
following to add numbers up to one million. And if you want to you can
extend it even further by adding a millions table to the query.
PARAMETERS [Increase Max # to:] Long;
INSERT INTO IntegerTable ( IntegerField )
SELECT
[IntegerTable].[integerField]+(([I_10].[IntegerField]-1)*10)+(([I_100].[integerField]-1)*100)+(([I_1000].[IntegerField]-1)*1000)+(([I_10000].[Integerfield]-1)*10000)+(([I_100000].[IntegerField]-1)*100000)
AS NewNumber
FROM IntegerTable, IntegerTable AS I_10, IntegerTable AS I_100, IntegerTable
AS I_1000, IntegerTable AS I_10000, IntegerTable AS I_100000
WHERE
[IntegerTable].[integerField]+(([I_10].[IntegerField]-1)*10)+(([I_100].[integerField]-1)*100)+(([I_1000].[IntegerField]-1)*1000)+(([I_10000].[Integerfield]-1)*10000)+(([I_100000].[IntegerField]-1)*100000)>(Select
Max(IntegerField) FROM IntegerTable) And
[IntegerTable].[integerField]+(([I_10].[IntegerField]-1)*10)+(([I_100].[integerField]-1)*100)+(([I_1000].[IntegerField]-1)*1000)+(([I_10000].[Integerfield]-1)*10000)+(([I_100000].[IntegerField]-1)*100000)<=[Increase
Max # to:] AND ((IntegerTable.IntegerField)<11) AND ((I_10.IntegerField)<11)
AND ((I_100.IntegerField)<11) AND ((I_1000.IntegerField)<11) AND
((I_10000.IntegerField)<11) AND ((I_100000.IntegerField)<11);
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
rich said:
Hello,
I have an application where I need to generate sequential number in the
range 1-99999. I have a table which will have one column storing these
numbers.
tblSeqNumbers
SeqNum Integer PK
I need to:
1. Query the table to determine the highest number.
Either of these will work but not sure if one is better than the other.
A. Select count (*) from tblSeqNumbers
B. SELECT max (SeqNum ) FROM tblSeqNumbers;
2. Store the value returned to a variable.
3. Add 1 to the number returned.
4. Insert the new value back into the table.
Can anyone tell me how to assign the value returned from the query to a
variable?
TIA,
Rich