Results 1 to 7 of 7
  1. #1
    kstaker
    Guest

    Forms (Word 2000)

    I am building a form in Word and I want to make a portion of it to have a number that will add one everytime the form is opened. How can I do this. In Wordperfect you can create a macro and the document will pull the macro when it opened and whatever the check request number was it will add one number to it and so on. I want to do this in word, HELP!!!

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms (Word 2000)

    Hi Kim:
    I'm not a VBA expert, but I do save tips. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Here's one I haven't tried that I copied, I "think" from Allen Wyatt, who publishes a WordTips newsletter (http://www.vitalnews.com/wordtips/).

    Numbering Documents Sequentially
    Using Sequential Document Serial Numbers
    If you have a need to create serial numbers in your documents and they are very simple in nature, you can do so using a macro. This approach to serial numbers is great if your serial numbers are sequential (1, 2, 3, etc.) or regular in their incidence (3, 5, 7, etc.).

    To begin, you should enter the macro that will control the change of the serial number and the printing of your document. The following VBA macro will do the trick:

    Sub MySerial()
    Dim rngSerialLocation As Range
    Dim intSerialNum As Integer
    Dim strSerialNum As String
    Dim docCurrent As Document
    Dim intNumCopies As Integer
    Dim intCount As Integer

    ' set ref to current active doc
    Set docCurrent = Application.ActiveDocument
    ' set ref to the bookmarked serial number
    Set rngSerialLocation = docCurrent.Bookmarks("Serial").Range

    ' get the starting number
    intSerialNum = Val(rngSerialLocation.Text)
    ' get the number of copies required
    intNumCopies = Val(InputBox$("How many Copies?", "Print Serialized", "1"))

    For intCount = 1 To intNumCopies
    ' print the document
    docCurrent.PrintOut Range:=wdPrintAllDocument
    ' increment the serial number
    intSerialNum = intSerialNum + 1
    ' put into formatted version
    strSerialNum = Format(intSerialNum, "00000")
    ' stuff into proper place
    rngSerialLocation.Text = strSerialNum
    Next intCount

    ' reset the bookmark, since the updating procedure
    ' wipes out the old one
    docCurrent.Bookmarks.Add Name:="Serial", Range:=rngSerialLocation

    End Sub

    Regardless of which macro version you use, there is only one prerequisite: you need to make sure that your document contains a bookmark named Serial. This bookmark should reference the serial number in your document, as you want it to appear in the first printed document. (When you are through running the macro, you can save the document and the serial number will be ready for the next time you want to use it.)

    In addition, the macros make a couple of other assumptions. First, it is assumed that your serial number consists primarily of some numeric value that changes with each iteration. You can you can modify the incrementing of the serial number, as well as its formatting, in the For...Next loop within the macro.
    Using Unique Document Serial Numbers
    There may be times you want to include a unique serial number in your documents, and the serial numbers much be specific and non-sequential. For instance, the first serial number could be X2417, the next one X2428, the third X2435, etc.

    Assuming you know what serial numbers you need to use, the quickest way to handle this situation is to use the mail-merge features of Word to create your final documents. To do this, follow these general steps:

    1. Create a document that contains nothing but the serial numbers.
    2. Put the serial numbers in a table, one serial number per row. Make sure there is a header on the table, and the header is named something like "Serial Number."
    3. Load your target document, the one you want to contain the serial number.
    4. Choose Mail Merge from the Tools menu. This displays the Mail Merge Helper dialog box.
    5. Go through the steps of specifying your main document (the one you loaded in step 2) and your data source (the one you created in step 1).
    6. In your main document, insert a merge field that indicates where you want the serial number to appear.
    7. Print your mail-merged documents.

    The primary advantage of this approach is that you can use non-sequential serial numbers. You can also change the contents of your serial number file whenever you need a new batch of documents, and simply print again.

    You may also wish to look at this article.

    Hope this helps.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Forms (Word 2000)

    If you are creating a template and want every new document based on a template to have a sequential number, check out earlier discussions of how to implement invoice numbers in Word. For example, Post #66546 et seq.

  4. #4
    kstaker
    Guest

    Re: Forms (Word 2000)

    I found a script that worked great for me and I was able to get it to start with the number I needed it to start with BUT NOW, when I protect the form it won't work!! HELP AGAIN!!! I have attached the form and the script that I used is: The bookmark is named "Object", The Script is:

    Sub AutoNew()

    Order = System.PrivateProfileString("C:Settings.Txt", "MacroSettings", "Order")

    If Order = "" Then
    Order = 8500
    Else
    Order = Order + 1
    End If

    System.PrivateProfileString("C:Settings.txt", "MacroSettings", "Order") = Order

    ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#")
    ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")

    End Sub

  5. #5
    kstaker
    Guest

    Re: Forms (Word 2000)

    I used your advice and I was able to come up with a macro based on the other article that you suggested. What I am wondering now is that everthing works and I was able to tell it what number I wanted the invoives to start with the problem is that when I protect the document I get and error when I go back into it. Please refer back to my post, for the error, the script and the document as an attachement. Thanks Kim

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Forms (Word 2000)

    I think you need the document to be unprotected before you insert the text. You either can have it be unprotected in the template and then insert the text and protect it in code, or you can unprotect and then reprotect it.

    Another option would be to assign the value to a field that cannot be edited by the user. So, as shown in the attached, clear the Fill-in enabled checkbox, and assign the value this way:

    ActiveDocument.FormFields("OrderNo").Result = Format(Order, "00#")

    This would not require you to unprotect the Form. I don't know if it has any other good or bad consequences, since I have created a grand total of one actualy useful form. (I didn't run your macro as written to avoid accumulating stuff in my registry. But I'm not sure you have allowed enough digits in your Format string.)

    Hope this helps.
    Attached Images Attached Images

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Forms (Word 2000)

    Thread continues on VBA board with <!post=Post #169305,169305>Post #169305<!/post>.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •