AutoIncrement field each time document is printed ?

  • Thread starter Roberto Carabajal
  • Start date
R

Roberto Carabajal

Hello:

I have read notes like -Creating sequentially numbered documents (such as
invoices)- but could not find exactly what I am looking for.
Please I would appreciate advice in this case. I have a simple document, and
want to show a field or textbox (really cannot decide wich of them) that
autoincrement in 1 each time the doc is saved. It is convenient to protect
that number from other user changes. I have experience in Excel VBA but Word
objects are still a bit stranger for me, so please, show me the details.
My best regards.
Roberto
 
D

Doug Robbins - Word MVP

It sounds like the method in the article "Creating sequentially numbered
documents (such as
invoices)" is exactly what you need to use. Why doesn't it work for you?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Roberto Carabajal

Well, perhaps I'm not doing the right way. Please, can you give details about
the steps neccesary to do:
'In the template from which you create the document, insert a bookmark named
Order in the location where you want the sequential .........'

I will follow that carefully to test what I'm doing.
 
G

Graham Mayor

Open the document template in Word. Put the cursor at the place in the
template where you want the number to be displayed. From the Insert menu
(Word 2003) select Bookmark. Type the name RecNo.
Add the following macros to the template

Sub AutoNew()
Dim SettingsFile As String
Dim Order As String
Dim rRecNo As Range
Dim i As Long

SettingsFile = Options.DefaultFilePath(wdStartupPath) & "\Settings.ini"
Order = System.PrivateProfileString(SettingsFile, _
"DocNumber", "Order")
If Order = "" Then
Order = 1
End If
Set rRecNo = ActiveDocument.Bookmarks("RecNo").Range
rRecNo.Text = Format(Order, "00000")
With ActiveDocument
.Bookmarks.Add "RecNo", rRecNo
.Fields.Update
.ActiveWindow.View.ShowFieldCodes = False
End With
Order = Order + 1
System.PrivateProfileString(SettingsFile, "DocNumber", _
"Order") = Order
End Sub


Sub ResetReceiptNo()
Dim SettingsFile As String
Dim Order As String
Dim sQuery As String
SettingsFile = Options.DefaultFilePath(wdStartupPath) & "\Settings.ini"

Order = System.PrivateProfileString(SettingsFile, _
"DocNumber", "Order")
sQuery = InputBox("Reset start number?", "Reset", Order)
If sQuery = "" Then Exit Sub
Order = sQuery
System.PrivateProfileString(SettingsFile, "DocNumber", _
"Order") = Order
End Sub

Add the second macro to a toolbar button in the template.
Save and close the template.
Create a new document from the template
The number will be entered at the bookmarked location starting from 1. Use
the reset macro to set an alternative start number.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Roberto Carabajal

Thanks, Thanks very much !!!

Graham Mayor said:
Open the document template in Word. Put the cursor at the place in the
template where you want the number to be displayed. From the Insert menu
(Word 2003) select Bookmark. Type the name RecNo.
Add the following macros to the template

Sub AutoNew()
Dim SettingsFile As String
Dim Order As String
Dim rRecNo As Range
Dim i As Long

SettingsFile = Options.DefaultFilePath(wdStartupPath) & "\Settings.ini"
Order = System.PrivateProfileString(SettingsFile, _
"DocNumber", "Order")
If Order = "" Then
Order = 1
End If
Set rRecNo = ActiveDocument.Bookmarks("RecNo").Range
rRecNo.Text = Format(Order, "00000")
With ActiveDocument
.Bookmarks.Add "RecNo", rRecNo
.Fields.Update
.ActiveWindow.View.ShowFieldCodes = False
End With
Order = Order + 1
System.PrivateProfileString(SettingsFile, "DocNumber", _
"Order") = Order
End Sub


Sub ResetReceiptNo()
Dim SettingsFile As String
Dim Order As String
Dim sQuery As String
SettingsFile = Options.DefaultFilePath(wdStartupPath) & "\Settings.ini"

Order = System.PrivateProfileString(SettingsFile, _
"DocNumber", "Order")
sQuery = InputBox("Reset start number?", "Reset", Order)
If sQuery = "" Then Exit Sub
Order = sQuery
System.PrivateProfileString(SettingsFile, "DocNumber", _
"Order") = Order
End Sub

Add the second macro to a toolbar button in the template.
Save and close the template.
Create a new document from the template
The number will be entered at the bookmarked location starting from 1. Use
the reset macro to set an alternative start number.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top