Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    Autonumbr (Office XP)

    Hi

    Can anyone tell if the following is possible, I have a fax template in which we to enter a number each time we use it, is it possible to insert a field which will create a new number each time it is opened

    Thanks

    Braddy
    If you are a fool at forty, you will always be a fool

  2. #2
    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: Autonumbr (Office XP)

    To create an incremental counter, one approach is to create a custom document property or a document variable, and an AutoOpen macro to increment it. You can cause either of those values to appear in the document using Insert>Field, DOCPROP or DOCVAR and then the name of the property or variable. The template must be saved in order to make this work, so if it's read-only (by virtue of being shared/opened by multiple people), you might have to store the number outside the template.

    When search returns, you can find more options (e.g., INI files, database files, etc.) by searching for "invoice number" on the Word and VBA boards.

    Now, if you wanted a random number, that won't be duplicated, I think the mathematicians will need to join the thread. <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Autonumbr (Office XP)

    Hi John

    Looks very interesting what you say, and managed to do it with the Author, but I don't understand how to get a numbered field as in my original request.

    Thanks

    Braddy
    If you are a fool at forty, you will always be a fool

  4. #4
    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: Autonumbr (Office XP)

    Sorry, no time to code this now. Here's an example from the Lounge's past of how to use an INI file to insert a number at a bookmarked location:
    <hr>Subject: Re: Code for Sequential Numbering an Invoice Template (Word97) [#141695]
    Poster: Hubert_NY
    Posted on: 20-May-02 14:25

    The challenge here seems to be finding a place to save the last used invoice number. There are lots of ways you could do this (as a doc property attached to the template, in the Windows Registry, etc.); however, here's an example using an INI file.

    First, create the INI file, which should be a text file (in this example, the text/INI file is saved at "c:tempInvoiceNum.ini") containing the following text...

    [InvoiceNums]
    LastNumber=501

    The following sub uses this INI file and increments it accordingly:

    Sub IncrementInvoiceNum()
    Dim lngInvoiceNum As Long
    'Fetch the Last Used Invoice Number and Increment it
    lngInvoiceNum = CLng(System.PrivateProfileString("C:TempInvoiceNum .ini", _
    "InvoiceNums", "LastNumber")) + 1
    MsgBox lngInvoiceNum
    'Or type the invoiceNum at the bookmark
    'Selection.GoTo What:=wdGoToBookmark, Name:="bkNumber"
    'Selection.TypeText Cstr(lngInvoiceNum)
    'Set the Last Used Invoice Number for next time
    System.PrivateProfileString("C:TempInvoiceNum.ini" , _
    "InvoiceNums", "LastNumber") = CStr(lngInvoiceNum)
    End Sub

    Hubert<hr>
    You would call that code from a macro named AutoOpen (or perhaps AutoNew?) or an event handler in ThisDocument called Document_Open (or perhaps Document_New?). The difference between Open and New is what you would expect: the Open code runs every time you open a document, while the New code only runs when the document is first created from the template.

    When the old posts come back, you can use the links in <post#=259241>post 259241</post#> for additional approaches.

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Autonumbr (Office XP)

    Hi Hubert

    Thank you for your response I will give it whirl.

    Thanks again

    Braddy
    If you are a fool at forty, you will always be a fool

Posting Permissions

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