WD: Using WordBasic to Add Sequential Number to Form Document |
Q119990
With Microsoft WordBasic, you can produce a series of document forms with a number that is incremented with each new document created. This may be helpful if you are designing an invoice template form and you want to automatically increment the invoice number. The following macro example increments the value stored in the INVOICE# AutoText entry each time the macro is run and places the result in a text form field called Invoice_Number.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please see the following page on the World Wide Web:
http://www.microsoft.com/partner/referral/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://support.microsoft.com/directory/overview.aspTo create the sample macro, follow these steps:
Sub Main
End Sub
Sub MAIN
' Unprotect form so an AutoText entry can be changed.
ToolsUnprotectDocument
' Retrieve the contents of the INVOICE# AutoText entry and
' add 1 to it.
number = Val(GetAutoText$("INVOICE#", 1)) + 1
' Convert the number to a string variable.
InvoiceNum$ = Str$(number)
' Remove the preceding space.
Temp$ = LTrim$(InvoiceNum$)
' SET the contents of the INVOICE# AutoText entry.
SetAutoText "INVOICE#", Temp$, 1
' Set the contents of the Invoice form field.
SetFormResult "Invoice_Number", Temp$
' Re-Protect the current document for forms.
ToolsProtectDocument .Type = 2, .NoReset = 1
' Save the template.
SaveTemplate
End Sub 100000
Sub MAIN
number = Val(GetDocumentVar$("number")) + 1
number$ = LTrim$(Str$(number))
SetDocumentVar "number", number$
SetFormResult "Text1", number$
End Sub
You can assign this macro to a form field as an on-exit or on-entry macro.
This way, the contents of the Text1 form field are automatically
incremented when the form field is entered or exited.
"Microsoft Word Developer's Kit," version 6.0, pages 183-198
Additional query words: form text field macro SetFormResult auto serial increment sequential seq sequence incremental automatically
Keywords : kbmacro kbmacroexample winword macword word6 word7 word95
Issue type : kbhowto kbinfo
Technology : kbHWMAC kbOSMAC kbWordSearch kbWordMacSearch kbWord700Search kbZNotKeyword2 kbWord600Mac kbWord601Mac kbWord600 kbWord600a kbWord600c kbWord700 kbWord700a
|
Last Reviewed: December 30, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |