Calling the Transaction Server Object


When the user clicks the Received button, we can create a reference to the Transaction Server object that we have created by using the code snippets that we saw earlier, and can display for the user the resulting in stock and back order amounts with the code in Listing 28.5.

Listing 28.5 - RECVNG.FRM - The method used to create a reference to our Transaction Server object, and call the method that we created in the object.

Private Sub cmdReceived_Click()
    Dim iBackOrder As Integer
    Dim iCurInventory As Integer
    Dim ProgID As String
    Dim obj As Object
    
    'Set up the error handling
    On Error GoTo ErrorHandler
    
    'Decide which component to use
    ProgID = "InvMaint.InvMnt"
    
    'Create the appropriate object
    Set obj = CreateObject(ProgID)
    'Were we able to create the object?
    If obj Is Nothing Then
        MsgBox "Create object " + ProgID + "failed."
        Exit Sub
    End If
    'Call the object method
    If obj.ChangeInv(iiProductID, CLng(txtCount.Text), iBackOrder, _
                                iCurInventory) = -1 Then
        Err.Raise ERROR_NUMBER
    End If
    
    'Release the object
    Set obj = Nothing
  
    'Display for the user what the current inventory is
    MsgBox "New Inventory received, current backorder count = " _
              + Str$(iBackOrder) + " and current inventory = " _
              + Str$(iCurInventory)
    Exit Sub
    
ErrorHandler:
    'Show the user the error message
    MsgBox "Error " + Str$(Err.Number) + " : " + Err.Description
    Exit Sub
End Sub

Before we run our form, let's change the view in the Transaction Server Explorer to show the status of our object. We do this by selecting the Components folder in the package we have created. Next, choose View, Status. The right side of the Explorer will now show us the activity status of our object. If you run the form with the Transaction Server Explorer where it can be seen, you can watch as the object that we created earlier is instantiated and executed, as seen in Figure 28.23.

Figure 28.23

When the form that we have created calls the object that we registered in Transaction Server, you can see as the object is created and run.