How do I make a Microsoft Word form automatically add a form number?

I've created a more user friendly form for our tooling department to complete online (tabbed through when locked). I have two questions.

1. How do I add a drop down date field so they just pick the date versus typing it? I would like it to open up to the current date when the form is opened.

2. Is there a way to add a field that will automatically add a serial/form number (no particular sequence) to the form? The reason I want that is because the printed copies go in a binder and some of the key data is in a spreadsheet for the VP (he runs reports from the data). He wants to be able to add a serial number to the form so that he can easily locate the hard copy in his binder if he needs to.
F730.5-Tool-Repair-Improvement-Form-DRAF
F730.5-Tool-Repair-Improvement-Form-UNLO
F730.5-Tool-Repair-Improvement-Form-CARL
Marcia MorrisProject ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
For the form number, you will need to keep a record of what numbers have been used, so sequential numbering is easiest. If there is only one user, the latest number can be saved in the registry. It would need some code like this in the ThisDocument module of the template.
Option Explicit

Private Sub Document_New()
    Dim lSerial As Long
    
    'Get latest serial number
    lSerial = CLng(GetSetting("Tool Repair", "Improvement", "Serial", 0))
    lSerial = lSerial + 1
    'Format and put into the new document
    ActiveDocument.FormFields("Serial").Result = Format(lSerial, "000000")
    'save the new latest serial number
    SaveSetting "Tool Repair", "Improvement", "Serial", CStr(lSerial)
End Sub

Open in new window

If there is more than one user, the data could be saved in a file on the server.
GrahamSkanRetiredCommented:
You should be able to add an ActiveX control to  the form to set the date.
Use the hammer and spanner symbol in the ActiveX controls  section to get a list of more controls. The 'Microsoft Date and Time Pickers' should be there.

You can add a line to the code to set it to today's date:

Option Explicit

Private Sub Document_New()
    Dim lSerial As Long
    
    'Get latest serial number
    lSerial = CLng(GetSetting("Tool Repair", "Improvement", "Serial", 0))
    lSerial = lSerial + 1
    'Format and put into the new document
    ActiveDocument.FormFields("Serial").Result = Format(lSerial, "000000")
    'save the new latest serial number
    SaveSetting "Tool Repair", "Improvement", "Serial", CStr(lSerial)
    ActiveDocument.DTPicker1.Value = Now
End Sub

Open in new window

Marcia MorrisProject ManagerAuthor Commented:
GrahamSkan..how do I view the code in Word? I've added the Microsoft Date and Time Pickers' so thank you. Just can't figure out how to view the code to add the sequential numbering.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

GrahamSkanRetiredCommented:
Alt + F11 will open the VBA editor.

You should see the Project explorer pane on the left. Locate  the project for your template, and open it and then the Microsoft Word objects folder to find the ThisDocument module. Usually code is put into other modules than might be added, but we need to use that module because it is a class module so that Document event code will run when the event occurs. In the case of Document_New, that is when a new document is created from the template.

Paste the code into the code window on the right. Note that I have invented a form field called "Serial", so that must be added to the document, though you can change the code and give the field a different name. I notice in your unlocked sample document that none of the form fields have names, not even the default ones like "Text1", "Text2" and "Check1" etc.

To view or change a form field name, right-click and choose 'Properties' from the context menu.  Enter the chosen name into the 'Bookmark' box and hit OK
Rob HensonFinance AnalystCommented:
To throw a curve ball, as they say, does it have to be in Word?

There are numerous templates on the MS Website for Excel forms; they can be stored as a template and linked to a list in another workbook for storing the serial number and related data.

Thanks
Rob
Marcia MorrisProject ManagerAuthor Commented:
Rob Henson... it doesn't have to be in Word. I haven't had any experience with creating a form in Excel. I will do a google search and see what templates are available. Linking to a list would be ideal.
Marcia MorrisProject ManagerAuthor Commented:
Rob...I added the code and the field and named it 'serial' but I'm doing something wrong as the field isn't adding a serial number upon opening. I've attached the file.
F730.5-Tool-Repair-Improvement-Form-UNLO
GrahamSkanRetiredCommented:
Code written specifically for Word won't work in Excel (if that's what you are doing).
GrahamSkanRetiredCommented:
Here is your form as a template with two fields added, one for the form serial number and one for the current date. I've put them on the title bar, but you might prefer them to be elsewhere.

The code is in the template which is protected (without a password). To run it you need to create a new document from the template, either via File/New or by double-clicking on the template name in Windows Explorer.

Note EE won't accept a .dotm extension, so I've renamed is as .dotx. You will need to put it back to .dotm for it to work.
F730.5-Tool-Repair-Improvement-Form-1-.d

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GrahamSkanRetiredCommented:
Hmm. I now see that the name was too long for here and has cut off after the .d.
Marcia MorrisProject ManagerAuthor Commented:
GrahamSkan, forive me for the delayed response, got put on a project that required a significant amount of my time. The serialization worked great. I did run into an issue. I tried to add back in the 'Microsoft Date and Time Pickers' date and parts due date but I kept getting an error message that says 'date picker cannot be insert around the current selection'. Do you know of a reason why I wouldn't be able to add it back?

Also, when I tested the serialization it did exactly what I wanted it to do but once I implement it how do I get it to start the numbering over vs. from where I left off in this testing phase?
GrahamSkanRetiredCommented:
Sorry Marcia, I missed your last comment.

Have you resolved the issues?

I haven't see the error message before, so I think I'd need to know a few more details.

To restart the numbering, you would to have some code like this:
SaveSetting "Tool Repair", "Improvement", "Serial", 0

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Office Productivity

From novice to tech pro — start learning today.