Public Sub invoiceDistAttribs()
    Dim oInvoice As CAPInvoice
    Set oInvoice = New CAPInvoice
    
    Dim oDist As IBBDistribution
    
    Dim oDistAttrib As IBBAttribute
    Dim oAttribAPI As IBBAttributesAPI
    
    Dim lAttribTypeID As Long
    
    
    'For use with the Attribute type server
    Dim oServices As FE_Services
    Set oServices = New FE_Services

    Dim oATS As CAttributeTypeServer

    oServices.Init fe_application.SessionContext
    Set oATS = oServices.CreateServiceObject(bbsoAttributeTypeServer)

    oATS.Init fe_application.SessionContext, bbGlobalAttributeType_GLTransaction
    
    'Name the attribute we're looking for for later use
    lAttribTypeID = oATS.GetAttributeTypeID("SomeAttribute")
   
    'Early cleanup of Attribute Type Server and Services object
    oATS.CloseDown
    oServices.CloseDown
    Set oATS = Nothing
    Set oServices = Nothing
    
    
    With oInvoice
        .Init fe_application.SessionContext
        .Load 2188 '' Adjust to system ID of invoice
        
        'Loop through all Distributions on the invoice
        For Each oDist In .Distribution
            Set oAttribAPI = oDist.Attributes
            
            'Add a new Attribute to the distribution
            With oAttribAPI.Add
                .Fields(Attribute_fld_ATTRIBUTETYPESID) = lAttribTypeID
                .Fields(Attribute_fld_VALUE) = "Value or Description of Attribute"
                .Fields(Attribute_fld_ATTRIBUTEDATE) = Date
                .Fields(Attribute_fld_COMMENTS) = "Generic Comment"
            End With
            
            'List all Attributes on the distribution
            For Each oDistAttrib In oAttribAPI
                With oDistAttrib
                    Debug.Print "ATDataType: " & .AttributeDataType
                    Debug.Print "ATRecordType: " & .AttributeRecordType
                    Debug.Print "MustBeUnique: " & .MustBeUnique
                    Debug.Print "Desc: " & .Fields(Attribute_fld_VALUE)
                    Debug.Print "ShortDesc: " & .ShortDescription
                    Debug.Print "Date: " & .Fields(Attribute_fld_ATTRIBUTEDATE)
                    Debug.Print "Comment: " & .Fields(Attribute_fld_COMMENTS)
                    Debug.Print "..."
                End With
            Next oDistAttrib

        Next oDist
    End With
    
    'Validate and Save
    oInvoice.Validate
    oInvoice.Save
    
    'cleanup
    oInvoice.CloseDown
    Set oInvoice = Nothing
End Sub



VBA/API Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Our Customer Support can help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality. If you are interested in learning more about the VBA and API modules, contact your account manager.