Creating a controlled sequencial number

Q

QC

I am trying to create a sequencial invoice number from a starting point. I am
running a append query and want to input a starting invoice number on a form,
and then the query will advance the invoice number by 1 for each invoice
generated. I have it working by using an auto number for the invoice but I
need to input the starting number and go from there.

Or is there a better way.

Thanks
 
T

Tom Collins\(Home\)

| I am trying to create a sequencial invoice number from a starting
point. I am
| running a append query and want to input a starting invoice number
on a form,
| and then the query will advance the invoice number by 1 for each
invoice
| generated. I have it working by using an auto number for the
invoice but I
| need to input the starting number and go from there.
|
| Or is there a better way.
|
| Thanks

If it's strictly a number then you can use an AutoNumber field. These
normally start at 1, but there is a way to set a different starting
number. Access won't let you enter a different number either in form
view or dataset view. It will let you append a different number using
an Append query. Here's the steps you would go though:
1. Create a copy of the table that has your invoice number (We'll call
the original table A and the copy table B). The table will have to be
empty for this to work.
2. Depending on what it when you started, make sure Invoice Number in
table A is AutoNumber and Long Integer in table B.
3. Populate a dummy record in table B with the Invoice Number ONE LESS
than what you want to start with. If you want your invoice numbers to
start at 1000, put in 999.
4. Using an append query, append table B into table A.
5. You can now delete that dummy record in table A. The next record
will automatically be 1000 and so on.

2 words of warning.
1. DO NOT compact the database while table A still empty. Doing so
will reset the 'next record number' to 1.
2. If someone starts a new record and then cancels out of it, the
number is still used up. This will cause a gap in the sequence
numbers.


Also, as Joseph said, you could also do this with VBA. Look at locking
the field, the Before Insert event, and running a query to get the
next number.

Tom Collins
 
M

M.L. Sco Scofield

Depending on what you need, these articles might have some useful
information.

For an ADO version. This will also work in 2002 and 2003.
http://support.microsoft.com/default.aspx?scid=kb;en-us;210194
(There is some supplemental information at
http://support.microsoft.com/default.aspx?scid=kb;en-us;240317.)

For a DAO version. This will work in 2000, 2002 and 2003 as long as you have
a DAO reference set.
http://support.microsoft.com/default.aspx?scid=kb;en-us;140908
(There is some supplemental information at
http://support.microsoft.com/kb/191253/EN-US/.)

Good luck.

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Denver Area Access Users Group Vice President www.DAAUG.org
MS Colorado Events Administrator www.MSColoradoEvents.com
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
 
Top