Now that we have a component built and registered with Transaction Server, how do we call the method in this object from a Visual Basic application? First, the Visual Basic application has to get a reference to the Transaction Server object. Once the reference has been acquired, then the object's methods can be called. There are three ways that a reference to a Transaction Server objects can be acquired:
Using the CreateObject function
Using the GetObject function
Using the New keyword
![]()
There is a fourth method for acquiring a reference to a Transaction Server object by another Transaction Server object, and that is through the use of the Context Object's CreateInstance method, which creates the object reference in the same transaction context of the current object (depending on the new object's transaction attribute). We'll see this method in use in the following chapters.
From a Visual Basic application, we can create our reference to our Inventory Maintenance object with the following code:
Dim obj As Object Set obj = CreateObject("InvMaint.InvMnt")
![]()
The same Transaction Server object could have been created using the New keyword by using the following code:
Dim obj As New InvMaint.InvMntAs a general rule, all Transaction Server components can be referenced in the same way as all other ActiveX server objects. Transaction Server works with the Operating System to make sure that when Transaction Server components are requested, they are created and called within Transaction Server.
From here, we can call the object methods by referencing them via the object we have just created, as so:
obj.ChangeInv(iiProductID, CLng(txtCount.Text), iBackOrder, iCurInventory)
So if we build a simple little applet using the Remote Data Control and the Data Bound Combo Box, we can call our object and see how Transaction Server works. The first thing we will need to do is to add the Remote Data Control and the Data Bound List Controls to our Tool Palette. We do this by choosing Project, Components, as seen in Figure 28.21.
You have to include the Data Bound List Controls and the Remote Data Control into your Visual Basic project before you can use them.
With these two controls, we can build a simple form that provides a drop-down list box, containing the product descriptions from the Products table in the database. We accomplish this by binding the Remote Data Control to the ODBC configuration we have set up for our database, providing the user name and password that we have configured, and using the following SQL to populate the Remote Data Control:
SELECT * FROM Products
Next, we specify the Remote Data Control as the row source for the Data Bound Combo Box, and specify the Prd_Desc column as the ListField, DataField, and BoundColumn. We'll add a text box for the user to enter the number to add or remove from the inventory, and we have the form seen in Figure 28.22. The complete source code for this form can be found on the CD.
We'll use a very simple form to call the method in the object we registered with Transaction Server.