Customers & Suppliers (Trading Partners)

Customers and Suppliers can be accessed through the TradingPartners object. The TradingPartners object exposes standard TASLink Collection properties and methods which are used to navigate the collection and retrieve the TradingPartner object we require.

First create a valid data connection (see Setup and Login for the TASLink Object).

Now create a reference to a TradingPartners object and set it to the TradingPartners object exposed through the TASLink object model.

Dim oCustomers As TASLink.TradingPartners
Set oCustomers = oSDK.TradingPartners

You can now get access to a particular TradingPartner object in the collection.

Dim oCustomer As TASLink.TradingPartner
Set oCustomer = oCustomers.item(1)

Retrieving Trading Partner Data

Set whether or not you want to include any suppliers in the collection and in what order you want the records in the collection presented:

oCustomers.IncludeSuppliers = False
oCustomers.SortBy = CustomerCode

You can then retrieve a specific customer record, either by using the built-in Lookup Form (see the Navigation section in the Appendices for details of the form) like this:

Set oCustomer = oCustomers.ProvideUserLookup()

Or by specifying an individual customer like this:

Set oCustomer = oCustomers("SURREY BUS")

And then provide information like this:

Debug.Print "Customer code: " & oCustomer.Customer_AccountCodeID & vbNewLine & "Customer name: " & oCustomer.Name

Maintaining Trading Partner Data

Adding a new Trading Partner Record

First create the required references to the the TradingPartners objects collection and to the TradingPartner object as described above. In this example we are creating a new Customer record, but the procedure is the same for creating a Supplier record.

Dim oCustomers As TASLink.TradingPartners
Dim oCustomer As TASLink.TradingPartner
Set oCustomers = oSDK.TradingPartners
'create a new Trading Partner object
Set oCustomer = oSDK.TradingPartner
oCustomers.SortBy = CustomerCode
oCustomers.IncludeSuppliers = False

We can prepopulate the TradingPartner object’s properties:

oCustomer.Customer_AccountCodeID = "ABC"

(Note that if the customer is also a supplier we can set oCustomer.Supplier_AccountCodeID = "ABC" too)

oCustomer.Name = "ABC Test Customer"
oCustomer.Customer_SalesPersonCodeID = "DEF"
'continue to set properties of new customer...

If oCustomers.Add(oCustomer) = False Then
	MsgBox "Could not add new customer: " &
	oSDK.Status.userReadableDescription
	'handle error
Else
	MsgBox "New customer '" & oCustomer.Name & "' (ID: '" & oCustomer.Customer_AccountCodeID & "') successfully added to TAS"
End If

Updating an existing Trading Partner Record

First retrieve the object as described in Retrieving Trading Partner Data above – in this example we are going to change the name of a Customer record.

oCustomers.SortBy = CustomerCode
oCustomers.IncludeSuppliers = False
Set oCustomer = oCustomers("SURREY BUS")
'Customer record must be locked immediately prior to update
If oCustomer.LockRecord Then
	oCustomer.Name = InputBox("Please enter the new name for: " &
	vbNewLine & _
	oCustomer.Name & ".", "Customer Name Change")
	'Set any other changed properties of customer...
	If oCustomers.UpdateRecord(oCustomer) = False Then
		MsgBox "Could not update the record: " &
		oSDK.Status.userReadableDescription 'handle error
	Else
		MsgBox "Successfully updated TAS customer name to: '" & _
		oCustomer.Name & "'."
	End If
Else
	MsgBox "Could not lock customer record: " &
	oSDK.Status.userReadableDescription
	'Try again???
End If