Microsoft KB Archive/921524

= How to programmatically link a document to a job in Small Business Accounting =

Article ID: 921524

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
This article contains a programming example that shows how to programmatically link a document to a job in Microsoft Small Business Accounting. Small Business Accounting lets users link certain documents to a job. You can also programmatically link a document to a job by using the Microsoft Small Business Accounting Software Development Kit (SDK).



MORE INFORMATION
The following programming example creates a new invoice in Northwind Traders. The code then retrieves an existing job and links the new invoice to the job.

Note Northwind Traders is a fictitious company that is used for demonstration in SBA.

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 = // initialize iSbi here

//This line specifies the customer for the transaction. ICustomerAccount cust = (ICustomerAccount) GetAccountByName(iSbi.CustomerAccounts, &quot;School of Fine Art&quot;);

// This line specifies the job for the transaction. IJobAccount job = (IJobAccount) GetAccountByName(iSbi.JobAccounts, &quot;New classroom wing&quot;);

// This code creates the invoice, sets the date, and assigns the invoice to the job. ISalesInvoice inv = iSbi.CreateSalesInvoice(false); inv.FinancialDateTime = DateTime.Now; inv.JobAccount = job;

// This line adds a service item line to the invoice.

IServiceItemAccount servItem = (IServiceItemAccount) GetAccountByName(iSbi.ItemAccounts, &quot;Plumbing labor (FF)&quot;);

// This line specifies the line item and the quantity. IItemLine docLine = (IItemLine) inv.CreateSalesInvoiceLine(DocumentLineType.ContractItemLineType); docLine.LineItem = servItem; docLine.Quantity = 2;

// This line saves the invoice. inv.Save;

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

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

// This line verifies that there is a column named Name. // If there is no column with this name, a runtime exception error will be received. if (dv.Table.Columns.Contains(&quot;Name&quot;)) {           dv.RowFilter = String.Format(&quot;Name='{0}'&quot;, acctName); }       // The IJobAccount table does not have a Name column. Therefore, the code will search on JobName. else if (dv.Table.Columns.Contains(&quot;JobName&quot;)) {           dv.RowFilter = String.Format(&quot;JobName='{0}'&quot;, acctName); }       // This line verifies that there is a column named ModifiedDateTime. // If there is no column with this name, a runtime exception error will be received. if (dv.Table.Columns.Contains(&quot;ModifiedDateTime&quot;)) {           dv.Sort = &quot;ModifiedDateTime DESC&quot;; }       // If there is more than one row, the code obtains the latest row. if (dv.Count > 0) {           row = dv[0].Row; }   }

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

return account; }

Additional query words: project

Keywords: kbexpertiseadvanced kbhowto KB921524

-

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

© Microsoft Corporation. All rights reserved.