Reset the "ItemNo." in BOM/ or Create a Counter in VBA

Hi all,

I have a problem, I creating a MML (Master Material List) and I need a column to populate atomatically. I have created a Custom Property Tab with a property called "Catagory" which the user should select one of the following:

As soon they have made their choice the settings is saved in the CustomProperties of the Part.

In the MML their is a Column called "BOM NO." in the column the type of the part is putted and the item number. for example, if I have two Steel structures and one Major equipment the list should took like this:

S1
S2
A1

But at the moment it looks like this:

S1
S2
A3

As you can see the numbering wont reset when the Catagory changes. This is the different "annotations" the different catagories have:

STEEL STRUCTURESS
MAJOR EQUIPMENTA
GROUNDINGG
CONDUCTORSB
CONNECTORSB
HARDWAREH
POWER CABLES & TERMINATIONSC
JUNCTION BOXESJ
TRENCH AND CONDUITT
MISCELLANEOUSM

I figured out how I get the correct annotations by a nested IF statement: (written as a equation in the column)

IF(`Category`="STEEL STRUCTURES"; "S"'ITEM NO.'; IF(`Category`="MAJOR EQUIPMENT"; "A"'ITEM NO.'; IF(`Category`="GROUNDING"; "G"'ITEM NO.'; IF(`Category`="CONDUCTORS"; "B"'ITEM NO.'; IF(`Category`="CONNECTORS"; "B"'ITEM NO.'; IF(`Category`="HARDWARE"; "H"'ITEM NO.'; IF(`Category`="POWER CABLES & TERMINATIONS"; "C"'ITEM NO.'; IF(`Category`="JUNCTION BOXES"; "J"'ITEM NO.'; IF(`Category`="TRENCH AND CONDUIT"; "T"'ITEM NO.'; IF(`Category`="MISCELLANEOUS"; "M"'ITEM NO.'; "FAIL TO SET VALUE, SEE ADMIN"))))))))))

I know that the "ITEM NO." only keep on going but I want to have some variable that is "reseted" when the catagory is changed. I belive that this problem could be solved thru some VBA coding but, I do not really know how.. could some one please help me!

Another idea I have is to create a new "counter" and put it in the CustomProperties, but I do not know how though..

Thanks in Advance!

Best Regards

Mattias

I have an Idea of how the code should look, but I do not now how I get it to work with Solidworks:

Catagory = String (existing in the Custom Property)

CatType = String

S_Value = integer, = 0

A_Value = integer, = 0

ItemNo. = number of items in the BOM

For I = 0 to ItemNO.

if Catagory = "Steel Structures" Then

CatType = "S"

S_Value = S_Value + 1

(Somehow Print 'CatType' and 'S_Value' together as a new variable and then point a BOM Column to that variable)

Else

If Catagory = "Major Equipment" then

CatType = "A"

A_Value = A_Value + 1

Else

.........

(Continue to the last Catagory)

..........

end if,

end if,

end the loop,

Reset all integer values

End Sub

SolidworksApi macros