Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Auto-incrementing Form Fields.

Auto-incrementing Form Fields

Written by Allen Wyatt (last updated December 18, 2021)
This tip applies to Word 97, 2000, 2002, and 2003


When you are working with forms, you save the forms as templates that are used as the basis of new documents in Word. There may be times when you want to add a form field that increments every time you create a new document based on your form template. For instance, you might have a sequence number that you need for a data input form, or you may want to use a form field to indicate an invoice number.

Word does not have any fancy auto-increment fields. However, by combining some of the tools already available in Word, you can create a template and form field to do the trick for you. Start with this macro:

Sub AutoNew()
   ' Exit macro if no fields in document
   If ActiveDocument.FormFields.Count = 0 Then Exit Sub
   ' Create variables.
   Dim OfficeAppName As String
   Dim RegSection As String
   Dim RegKey As String
   Dim FieldObj As Object
   Dim RegValue As Long

   OfficeAppName = "Word 2002"
   RegSection = "UserData"
   RegKey = "Current Counter"
   ' Generate error if form field doesn't exist
   On Error GoTo ErrHandler
   Set FieldObj = ActiveDocument.FormFields("IncField")
   ' Get stored registry value, if any
   RegValue = GetSetting(OfficeAppName, RegSection, RegKey, 0)
   ' If not previously set, set to default
   If RegValue = 0 Then RegValue = 1
   ' Set form field result to stored value
   FieldObj.Result = CStr(RegValue)
   ' Increment and update invoice number
   SaveSetting OfficeAppName, RegSection, RegKey, RegValue + 1
ErrHandler:
   If Err <> 0 Then
      MsgBox Err.Description
   End If
End Sub

This macro should be saved only in the template that you will use to create your forms. The macro must be named AutoNew, so it will run whenever a document is created that is based on the form template. You should also make sure that you have a text form field in your document named IncField, which will display the incremental number. The number is tracked in the Registry so it can be accessed for future forms.

Notice the line in the macro that sets the OfficeAppName variable. In this version of the macro, it is set to the phrase "Word 2002". If you are using a different version of Word, you should modify this line so it refers to your version, such as "Word 2000" or "Word 2003".

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1329) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Auto-incrementing Form Fields.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using the IRR Function

When working with finances, you often need to know the rate of return on a given investment. The most common type of ...

Discover More

Dictionary Shortcut Key

Need a quick way to display the dictionary or other grammar tools? Use one of the handy built-in shortcuts provided by Word.

Discover More

Shortcut Key for Non-Breaking Space

Most of the time you'll use regular spaces between words in a document, but there may be times you want to use a special ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (menu)

Entering Calculations in a Form Field

One of the many uses for Word is to create forms that can be easily filled in by other people. This is made possible by ...

Discover More

Making Common Information Accessible

Got a bunch of info that is common to a lot of your documents? Here's a way to get that information standardized among ...

Discover More

Stopping Automatic Changes from Being Tracked

Track Changes is a great feature for keeping track of what gets changed in a document. There are some things (such as ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 1 + 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.