Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numbering documents automatically

Status
Not open for further replies.

tilltek

Programmer
Mar 8, 2001
298
PH
I use a Word template from within ACT! to produce an invoice for various customers and with much help from the forum I'm getting there. What I was wondering now is, when printing these documents, is there any way to insert a sequential number? Or better still, some text and then a serial number?
Today I might send out 3 invoices and they would have a number "2003-001" "2003-002" "2003-003".
Tomorrow I print another invoice and it would automaticlly contain the field "2003-004".
Possible???
Ken F
 
Do I take it that lack of replies means it can't be done?
Oh well.
I figured there must be some sort of way to have a data file or list of numbers that a macro or VBA script could look up. But if it won't work, it won't work.
Thanks all the same.
Ken F
 
Ken

Perfectly doable, and yes you can have a data file that records the last used number; reads it, converts it to a number, adds one, and uses it to set a document property. Then you include that document property as a field in your document.

I used to have some code to do pretty much this (it actually created a filename rather than a doc property), but I don't have access to it any more.

Does this help at all? If you need more guidance, come back and let me know where the problem is.

HTH

Ben
 
Hi Ken,
You could use the registry for keeping track of a sequential number. The values will be entered in: HKEY_CURRENT_USER\Software\VB and VBA Program Settings

Code would look like this:
Private Sub GetDocNumber()

Dim sDocNumber As String
Dim iDocNumber As Integer
Dim sYear As String
Dim sYearNow As String

'read values from the registry
sDocNumber = GetSetting("ACT", "Invoices", "SeqNumber", "")
sYear = GetSetting("ACT", "Invoices", "Year", "")
sYearNow = Format(Now, "yyyy")

'if idocnumer = "" then this is the first document
'if sYear <> sYearNow, we entered a new year so we start again at 1 (f.e.)
If sDocNumber = &quot;&quot; Or sYear <> sYearNow Then
iDocNumber = 1
'else add one to the doc number
Else
iDocNumber = sDocNumber + 1
End If

'find the next number to use and add leading zero's
If iDocNumber < 10 Then
sDocNumber = &quot;00&quot; & iDocNumber
ElseIf iDocNumber > 9 And iDocNumber < 100 Then
sDocNumber = &quot;0&quot; & iDocNumber
End If


sDocNumber = sYearNow & &quot;_&quot; & sDocNumber

'so now you've got a new sequential number which you can put in
'f.e. a bookmark, documentproperties, documentname.....

'now enter the new values in the registry
SaveSetting &quot;ACT&quot;, &quot;Invoices&quot;, &quot;SeqNumber&quot;, iDocNumber
SaveSetting &quot;ACT&quot;, &quot;Invoices&quot;, &quot;Year&quot;, sYearNow

End Sub

If you don't want to or are not allowed to enter any values in the registry you can do a simular thing using an ini-file.

Hope this helps.

Regards,
Unica
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top