Microsoft KB Archive/920193

= How to adjust inventory quantities programmatically by using the Small Business Accounting Software Development Kit together with the IInventoryAdjustment interface =

Article ID: 920193

Article Last Modified on 2/6/2007

-

APPLIES TO


 * Microsoft Office Small Business Accounting 2006
 * Microsoft Office Small Business Accounting 2006 Software Development Kit 1.2
 * Microsoft Office Small Business Management Edition 2006

-





INTRODUCTION
Microsoft Small Business Accounting lets users adjust inventory quantities. You can adjust inventory quantities programmatically by using the Small Business Accounting Software Development Kit (SDK) together with the IInventoryAdjustment interface.



MORE INFORMATION
The following code creates one inventory adjustment that decreases quantities for two items in the Northwind Traders company.

Note Northwind Traders is the fictitious company that is used for demonstration in Small Business Accounting.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. ISmallBusinessInstance iSbi = // The iSbi variable is instantiated here.

IFinancialAccount ifa = (IFinancialAccount) GetAccountByName(iSbi.FinancialAccounts, &quot;Other Expenses&quot;);

IInventoryAdjustment ia = iSbi.CreateInventoryAdjustment; ia.FinancialDateTime = DateTime.Now.AddDays(2); ia.FinancialAccount = ifa;

// The following line retrieves the first item for which you want to adjust the quantity. IInventoryItemAccount item1 = (IInventoryItemAccount) GetAccountByName(iSbi.ItemAccounts, &quot;Hockey Stick&quot;);

// The following line creates an array of adjustment lines that has two elements. IInventoryAdjustmentLine[] lines = new IInventoryAdjustmentLine[2];

lines[0] = ia.CreateInventoryAdjustmentLine; lines[0].InventoryItemAccount = item1; lines[0].AdjustedQuantity = -3;

// The following line retrieves the second item for which you want to adjust the quantity. IInventoryItemAccount item2 = (IInventoryItemAccount) GetAccountByName(iSbi.ItemAccounts, &quot;Hook&quot;);

lines[1] = ia.CreateInventoryAdjustmentLine; lines[1].InventoryItemAccount = item2; lines[1].AdjustedQuantity = -1;

// Persist the inventory adjustment to the database. ia.Save;

static IAccount GetAccountByName(IBaseMasterView view, string acctName) {   IAccount account = null; DataRow row = null;

if (view != null) {       DataView dv = view.DataView;

// Verify that there is a Name column, or a run-time exception occurs. if (dv.Table.Columns.Contains(&quot;Name&quot;)) {           dv.RowFilter = String.Format(&quot;Name='{0}'&quot;, acctName); }       // The IJobAccount does not have a Name column. Therefore, you must search by using JobName. else if (dv.Table.Columns.Contains(&quot;JobName&quot;)) {           dv.RowFilter = String.Format(&quot;JobName='{0}'&quot;, acctName); }       // Verify that there is a ModifiedDateTime column, or a run-time exception occurs. if (dv.Table.Columns.Contains(&quot;ModifiedDateTime&quot;)) {           dv.Sort = &quot;ModifiedDateTime DESC&quot;; }       // If there is more than one row, obtain the first row. if (dv.Count > 0) {           row = dv[0].Row; }   }

if (row != null) {       account = (IAccount) view.GetByDataRow(row); }

return account; }

Additional query words: IV SBA

Keywords: kbexpertiseadvanced kbhowto KB920193

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.