Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-23-2011, 03:11 PM
mslearner mslearner is offline Sequential numbering across multiple docs Windows XP Sequential numbering across multiple docs Office 2003
Novice
Sequential numbering across multiple docs
 
Join Date: Jun 2011
Posts: 2
mslearner is on a distinguished road
Default Sequential numbering across multiple docs

I'm creating a maintenance work-order system for a commercial property management company and need each work order to be sequentially numbered automatically upon opening. I've tried creating a field which ties to an original source document using the following:

{INCLUDETEXT "Drive:\\Filepath\\Filename.Extension"}
This simply inserts the entire original document into the field.

{INCLUDETEXT "Drive:\\Filepath\\Filename.Extension" \!}
This does the same as the above



and

{INCLUDETEXT "Drive:\\Filepath\\Filename.Extension" "bookmark name"}
This just shows a blank field with no data.

The field code that I have in the original document is: seq workorder \# 00# \r000501 \* MERGEFORMAT

What am I doing wrong here?
Reply With Quote
  #2  
Old 06-23-2011, 10:35 PM
macropod's Avatar
macropod macropod is offline Sequential numbering across multiple docs Windows 7 64bit Sequential numbering across multiple docs Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi mslearner,

That approach won't give you an automatically-incrementing work order number.

The following macro (which I wrote for invoice generation) inserts and increments a number from a text (ini) file. It should serve your needs equally well.
Code:
Private Sub Document_New()
Application.ScreenUpdating = False
Dim InvoiceFile As String, InvNum As String
'Save ini file in the Word startup folder.
InvoiceFile = Options.DefaultFilePath(wdStartupPath) & "\Invoice.ini"
'or, by using the following line, the Workgroup folder
'InvoiceFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\Invoice.ini"
InvNum = System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum")
'If there is no InvoiceNumber reference in the ini file
'Create one and set the number to 1, otherwise increment the number
If InvNum = "" Then
  InvNum = 1
Else
  InvNum = InvNum + 1
End If
System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") = InvNum
With ActiveDocument
  'Update the value stored in the document property
  .CustomDocumentProperties("InvNum") = InvNum
  'Update the fields in the document
  .Fields.Update
End With
Application.ScreenUpdating = True
End Sub
To use the code, you need to open your work order template and add the macro to its 'ThisDocument' code module.

Then, go to File|Info|Properties|Custom and add a document property named 'InvNum'.

Next, in the body of the work order template, position the insertion point where you want the work order number to appear and press Ctrl-F9 to create a pair of field braces (ie '{}') and type 'DOCPROPERTY InvNum' between the field braces, thus '{DOCPROPERTY InvNum}'. If you want to force the work order # to display leading 0s (eg 01234), add '\# 0000' to the field code, thus: '{DOCPROPERTY InvNum \# 0000}'.

Finally, save the template as a Word document Template (ie with a '.dot' (Word 2004 & earlier) or '.dotm' (Word 2007 & later) extension, via File|Save As), named 'Invoice' (or another suitable name).

Now, whenever you want to create a new work order, simply go to File|New and select 'work order' (or your preferred name). You'll get an work order with the next available number. The last-used number is held in a file named 'Invoice.ini' in your Word Startup folder. In case you need it, there's a commented-out line to store the 'Invoice.ini' in your Word Workgroup folder instead, so that others in your workgroup can access it also.

If you need to set the initial work order #, or reset it, you can do so manually, or use the following macro:
Code:
Sub ResetOrderNumber()
Dim InvoiceFile As String, InvNum As String
InvoiceFile = Options.DefaultFilePath(wdStartupPath) & "\Invoice.ini"
'or, if using a Workgroup folder
'InvoiceFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\Invoice.ini"
InvNum = System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum")
InvNum = Trim(InputBox("What is the last valid Work Order Number?" & vbCrLf & _
  "The current number is: " & InvNum))
If IsNumeric(InvNum) Then
  System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") = CInt(InvNum)
  End
Else
  If InvNum = "" Then End
End If
MsgBox "Renumbering error, please try again."
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-24-2011, 01:41 PM
mslearner mslearner is offline Sequential numbering across multiple docs Windows XP Sequential numbering across multiple docs Office 2003
Novice
Sequential numbering across multiple docs
 
Join Date: Jun 2011
Posts: 2
mslearner is on a distinguished road
Default

Thanks so much, this worked!
Reply With Quote
  #4  
Old 08-03-2012, 08:54 AM
Regency Regency is offline Sequential numbering across multiple docs Windows 7 32bit Sequential numbering across multiple docs Office 2007
Novice
 
Join Date: Aug 2012
Posts: 1
Regency is on a distinguished road
Default

Paul,
Im having trouble with setting up the system in Word 2007. I found and recorded the macro you posted but was unable to find where i could store the 'InvNum' system to make the numbering work.
Thanks,
April
Reply With Quote
  #5  
Old 08-03-2012, 08:33 PM
macropod's Avatar
macropod macropod is offline Sequential numbering across multiple docs Windows 7 64bit Sequential numbering across multiple docs Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi April,

You need to create a custom document property named 'InvNum'. IIRC, you get there in Word 2007 via:
Alt-f > Prepare > Properties > Document Properties > Advanced Properties > Custom.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 11-16-2012, 08:46 AM
raichea raichea is offline Sequential numbering across multiple docs Windows 7 64bit Sequential numbering across multiple docs Office 2010 32bit
Novice
 
Join Date: Nov 2012
Posts: 1
raichea is on a distinguished road
Default Almost there...

User error... all working now. Excuse the interruption... normal service will now be resumed.

Last edited by raichea; 11-16-2012 at 10:02 AM.
Reply With Quote
  #7  
Old 12-09-2014, 09:02 AM
jgreen90 jgreen90 is offline Sequential numbering across multiple docs Windows XP Sequential numbering across multiple docs Office 2003
Novice
 
Join Date: Dec 2014
Posts: 1
jgreen90 is on a distinguished road
Default Macros

What macros should I be adding this to?
Reply With Quote
  #8  
Old 12-09-2014, 01:13 PM
macropod's Avatar
macropod macropod is offline Sequential numbering across multiple docs Windows 7 64bit Sequential numbering across multiple docs Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As clearly stated in post #2, you add it to the document template.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 06-07-2019, 04:15 AM
wolfgrrl wolfgrrl is offline Sequential numbering across multiple docs Windows 10 Sequential numbering across multiple docs Office 2010
Novice
 
Join Date: May 2019
Posts: 15
wolfgrrl is on a distinguished road
Default

I realize that this is an old thread but I've been searching hours for a way to do this on a template. I've tried your macro and it's not functioning for me.

I get a compile error on the first line: ambiguous name detected: Document_New. I'm using Word 2010 and am opening my template from within Word.

Can you please help? Thank you!
Reply With Quote
  #10  
Old 06-07-2019, 04:47 AM
macropod's Avatar
macropod macropod is offline Sequential numbering across multiple docs Windows 7 64bit Sequential numbering across multiple docs Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The "ambiguous name detected: Document_New" message tells me that you already have a Document_New macro in the template. You can only have one such macro.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 06-07-2019, 05:15 AM
Charles Kenyon Charles Kenyon is offline Sequential numbering across multiple docs Windows 10 Sequential numbering across multiple docs Office 2016
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

If you give this macro a unique name, you can call it from the existing Document_New macro.
Reply With Quote
  #12  
Old 06-07-2019, 05:20 AM
macropod's Avatar
macropod macropod is offline Sequential numbering across multiple docs Windows 7 64bit Sequential numbering across multiple docs Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I'd be wanting to know what the existing one does before recommending that approach. Even assuming a call is appropriate, it may be so in one part of the existing macro but not in another.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 06-10-2019, 06:17 AM
wolfgrrl wolfgrrl is offline Sequential numbering across multiple docs Windows 10 Sequential numbering across multiple docs Office 2010
Novice
 
Join Date: May 2019
Posts: 15
wolfgrrl is on a distinguished road
Default Network location

Quote:
Originally Posted by macropod View Post
I'd be wanting to know what the existing one does before recommending that approach. Even assuming a call is appropriate, it may be so in one part of the existing macro but not in another.
Is it possible to store the ini file on a network location? How would one format the macro to work with that?

The network location is a mapped drive on all machines.
Reply With Quote
  #14  
Old 06-10-2019, 11:31 AM
wolfgrrl wolfgrrl is offline Sequential numbering across multiple docs Windows 10 Sequential numbering across multiple docs Office 2010
Novice
 
Join Date: May 2019
Posts: 15
wolfgrrl is on a distinguished road
Default

This is the code I'm using.

Code:
Private Sub Document_New()
Application.ScreenUpdating = False
Dim InvoiceFile As String, InvNum As String
InvoiceFile = Options.DefaultFilePath(wdDocumentsPath) = "N:\Engineering\ECN & ER Forms" & "\NUMBERS.ini"
InvNum = System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum")
'If there is no InvoiceNumber reference in the ini file
'Create one and set the number to 1, otherwise increment the number
If InvNum = "" Then
  InvNum = 1
Else
  InvNum = InvNum + 1
End If
System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") = InvNum
With ActiveDocument
  'Update the value stored in the document property
  .CustomDocumentProperties("InvNum") = InvNum
  'Update the fields in the document
  .Fields.Update
End With
Application.ScreenUpdating = True
End Sub
InvNum exists in custom properties.

NUMBERS.ini is stored in the same location as the form on the network.

Getting the error shown below. Can someone assist?

Reply With Quote
  #15  
Old 06-10-2019, 07:18 PM
macropod's Avatar
macropod macropod is offline Sequential numbering across multiple docs Windows 7 64bit Sequential numbering across multiple docs Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For your situation, it would probably be best to create a Custom Document Property named 'InvNum' in the template, then use code like:
Code:
Private Sub Document_New()
Application.ScreenUpdating = False
Dim InvNum As String
With ThisDocument
  InvNum = .CustomDocumentProperties("InvNum") + 1
  .CustomDocumentProperties("InvNum") = InvNum
  '.Save
End With
With ActiveDocument
  'Update the value stored in the document property
  .CustomDocumentProperties("InvNum") = InvNum
  'Update the fields in the document
  .Fields.Update
End With
Application.ScreenUpdating = True
End Sub
Do note that the number will increment every time a new document is created from the template. If someone does that, then doesn't save the new document, you'll invariably end up with gaps in the numbers in the saved documents. You can, of course, manually edit the 'InvNum' Custom Document Property in the template, but it's better to avoid the situation in the first place. More complex code could be used to ensure the numbers are only updated when the template is closed, but you then run the risk of the same number being allocated twice if two or more documents are being created at the same time.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sequential numbering across multiple docs How do I do a Sequential Numbering? gburya Word VBA 26 07-04-2017 03:29 PM
Sequential numbering across multiple docs Sequential Page Numbering of Multiple Word Docs bobmard Word 8 08-24-2011 08:51 AM
Sequential numbering across multiple docs Editing multiple docs frankdh Word 2 11-02-2010 10:59 AM
Please help with Numbering a document with multiple letters. DJReality213 Office 1 01-15-2010 05:56 PM
Amend footer in multiple word docs? compact Word 2 02-24-2009 09:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft