View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff[_6_] Harald Staff[_6_] is offline
external usenet poster
 
Posts: 21
Default Unique ID number generation

Adding to Tom, see if this can get you started. It's made for a multi user
environment:

Sub NewInvoiceNumber()
Dim ThisInvoice As Long
Dim ReadText As String
Dim StoreFile As String
'replace with network path\file name:
StoreFile = "C:\Temp\Number.num"
'read previous number:
If Dir(StoreFile) = "" Then 'not found
ThisInvoice = 1
Else
Open StoreFile For _
Input Access Read As #1
While Not EOF(1)
Line Input #1, ReadText
ThisInvoice = Val(ReadText)
Wend
Close #1
End If
ThisInvoice = ThisInvoice + 1
MsgBox "Invoice # " & ThisInvoice
'replace previous with "paste into sheet" code
'Store this number:
Open StoreFile For _
Output Access Write As #1
Print #1, ThisInvoice
Close #1
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Matt" skrev i melding
...
There is an invoive template in 97 that allocates a unique
number to the invoice when asked. I am trying to
replicate the code so that every time the sheet I have
created is opened and a command button used the next
number in a series is added to the sheet uniquely
identifying it. Any ideas please?