Sequential Record ID for Excel Template

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I hope somebody can help me
I am trying to create a template that will allow me to record a unique Record ID for each form generated from the template. (Kind of like an invoice number
Any Ideas

Thanks!
 
Sean

The way that I do this is store the last invoice number used in a text file.
Then when I want a new invoice number, my code retrieves the number,
increments it by one and writes the new number back to the text file.

If more than one person uses the template, you could have a problem where
they both get the old number before the new one is written. I'm the only
one that uses mine, so I haven't looked into how to prevent that. Here's
the code that I use:

Sub NextInv()

Dim FName As String
Dim FNum As Long
Dim LstInv As String

FName = "\\Server1\c\Paragon\Policies & Forms\LastInv.txt"
FNum = FreeFile

Open FName For Input As FNum
Input #FNum, LstInv

Close FNum

Range("B18").Value = CLng(LstInv) + 1

Open FName For Output As FNum
Print #FNum, CLng(LstInv) + 1
Close FNum

Sheet1.Shapes("Button 1").Visible = False

Range("g10").Select

End Sub

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

Sean Reilly said:
Hi, I hope somebody can help me.
I am trying to create a template that will allow me to record a unique
Record ID for each form generated from the template. (Kind of like an
invoice number)
 
Back
Top