Tina, if I understand your method, but pulling it once. incrementing,
then
how do I save the new number to incriment by one for the next time?
Optomyst, you're already saving each incremented invoice number *in the
invoice table*. why do you think you need to save it somewhere else as well?
and since you would have to retrieve it from that "somewhere else", why do
you think that you can't just as easily retrieve it from the invoice table?
are you
suggestinng I just assing the first number manually in the invoice table..
then nab the highest one it finds?
you have to "hard-code" the "first" invoice number anyway - regardless of
whether you enter it manually in a LastInvoiceNumber table, or write it into
the code, as
Me!InvoiceNumberField = Nz(DMax("InvoiceNumberField",
"InvoiceTableName"), 0) + 1
(again, the above is all on one line.)
look, just think through your process:
you enter a value of 0 in your LastInvoiceNumber table.
you enter the first invoice record in a form, where you run a DLookUp()
function to retrieve the value, which is currently 0.
you increment the value by 1, so 0 + 1 = 1.
you assign the incremented value 1 to the invoice record in the form.
you run an Update query to write the new value 1 back to table
LastInvoiceNumber.
you enter another new invoice record in the form, and run a DLookUp()
function to retrieve the value from table LastInvoiceNumber, which is
currently 1.
you increment the value by 1, so 1 + 1 = 2.
you assign the incremented value 2 to the invoice record in the form.
you run an Update query to write the new value 2 back to table
LastInvoiceNumber.
you enter another new invoice record in the form, and run a DLookUp()
function to retrieve the value from table LastInvoiceNumber, which is
currently 2.
you increment the value by 1, so 2 + 1 = 3.
you assign the incremented value 3 to the invoice record in the form.
you run an Update query to write the new value 3 back to table
LastInvoiceNumber.
you continue doing this, each time incrementing the last invoice number by
one, to assign the new invoice number. you could just as easily have
manually entered 499 in the LastInvoiceNumber table, to start your invoice
numbers at 500.
okay, now think through my process:
you enter the first invoice record in a form, where you calculate the value
of the invoice number from the expression
Nz(DMax("InvoiceNumberField", "InvoiceTableName"), 0) + 1
because it's the first invoice record, there is no "maximum" invoice number
in the table. so the Nz() function returns 0, to which 1 is added. so 0 + 1
= 1.
the invoice record is saved with an invoice number value of 1.
you enter another new invoice record in the form, where you assign the
invoice number from the expression
Nz(DMax("InvoiceNumberField", "InvoiceTableName"), 0) + 1
the DMax() function returns the highest invoice number in the table, which
is 1, to which 1 is added. so 1 + 1 = 2.
the invoice record is saved with an invoice number value of 2.
you enter another new invoice record in the form, where you assign the
invoice number from the expression
Nz(DMax("InvoiceNumberField", "InvoiceTableName"), 0) + 1
the DMax() function returns the highest invoice number in the table, which
is 2, to which 1 is added. so 2 + 1 = 3.
the invoice record is saved with an invoice number value of 3.
you continue doing this, each time incrementing the last invoice number by
one, to assign the new invoice number. you could just as easily have written
the expression to return 499 on the first "run", to start your invoice
numbers at 500, as
Nz(DMax("InvoiceNumberField", "InvoiceTableName"), 499) + 1
by comparing the two processes, step by step, you see that each one gives
you a invoice number of 1 for the first invoice record, the next invoice
record is assigned an invoice number of 2, the next invoice record gets a 3,
etc, etc, etc, etc. it doesn't matter if you want your invoice records'
invoice numbers to start with 1, or 100, or 50,000. you still have to "seed"
the first record in the invoices table, so you can seed it with whatever
beginning value you choose. and then each new invoice record is assigned an
invoice number that's incremented by 1, which is what you've been saying
that you want.
your choice is *not* between using one line of code *or* getting the
incremented invoice numbers you want. your choice is between getting the
incremented invoice numbers you want by using one line of code *or* by using
several lines of code and an additional table in the database.
hth