RW – Adding Line Numbers to SOP Documents Example

David Meego - Click for blog homepageThis is a reposting of an article I originally wrote on my Developing for Dynamics GP blog.

The following example shows how easy it is to use VBA to add a line number to a SOP Document.

There is a Knowledge Base (KB) article 857285 which uses the Line Item Sequence field and dividing its value by 16384 to obtain a line number.  This works… well … sort of.  As soon as a line item has been deleted or inserted, the Line Item Sequence field for the lines in the document will no longer be multiples of 16384 and so this method will start producing incorrect results.  This VBA example will always work.

By adding a blank calculated integer field to the SOP Blank Invoice Form at the beginning of the line item, we can then use VBA to populate this field with a value incremented as each line is printed.  We use the Report_Start() event to reset the counter variable and then use the Report_BeforeAH() event to increment the counter variable and update the calculated field.

NOTE: To ensure that only the H2 section is incrementing the counter, we use a select case statement in the Report_BeforeAH() event.

Example code for v8.0, v9.0 & v10.0 is attached at the bottom of the article.

Please see the “Installation Instructions.txt” file in each version’s archive for more information.

Line Numbers on SOP Invoice

This article was originally posted on the Developing for Dynamics GP Blog and has been reposted on

6 thoughts on “RW – Adding Line Numbers to SOP Documents Example

  1. Dear David,
    I need help on SOP Order Entry. I want to save the item line sequence number while user enter each item number.
    I managed to do so if NO Duplicate Item Number exists in SOP Order.
    Might I know how can I get the current line sequence number?


  2. Hi Jim
    I have checked the code and it seems that the Line Item Sequence field is populated as soon as the line is created.
    If you add the ‘Line Item Sequence’ field to VBA you will be able to obtain the value.  You might need to make it visible and move it into the scrolling window first. Or use the editing of the package method described in the following post:


Please post feedback or comments

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.