Results 1 to 4 of 4
  1. #1
    maryjanice92
    Guest

    Code for Sequential Numbering an Invoice Template (Word97)

    I have used the "Rnd" function to insert for a random number in a special requisition template form, so that each time the user runs the template, a new random number will appear. This number is used for filing. However, I would rather have a number start with, say, 500 and increase by one each time the template is generated so that the numbers will be sequential after the starting number. Can anyone help me with a snippet of code? Many thanks! The snippet of code I currently use in the template is as follows:

    Sub InvoiceRandomNumber()
    Dim snumber As Double
    Randomize

    snumber = Int((99999 * Rnd) + 11111)
    Selection.GoTo What:=wdGoToBookmark, Name:="bkNumber"
    Selection.TypeText snumber

    End Sub

  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Eugene, Oregon, USA
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code for Sequential Numbering an Invoice Template (Word97)

    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

  3. #3
    maryjanice92
    Guest

    Re: Code for Sequential Numbering an Invoice Template (Word97)

    Many thanks, Hubert! I will try your code example; I am sure it will do the trick! Thanks again for helping me out and for your quick response!...Mary

  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: Code for Sequential Numbering an Invoice Template (Word97)

    You might also check this earlier thread: Numbering invoices.

Posting Permissions

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