Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COM Component

Status
Not open for further replies.

sut

Programmer
Jun 6, 2001
12
0
0
US
I have 2 components called
COM1 and COM2

I call COM1 and then COM2, if COM2 fails to complete the transaction, i want to undo the transaction performed by COM1.

How can I call COM2 in COM1?

Waiting for suggestions
Thanks
Smita

 
You can call COM1 in COM2 by instantiating COM1 in COM2.
Here's a sample code:
COM2 Code:

Dim m_objCOM1 As COM1

Private Sub Class_Initialize()
Set m_objCOM1 = New COM1
'you can now call any public function/sub in COM1
'example:
'm_objCOM1.procProcessTransactions
End Sub

If COM2 fails, you can rollback transactions from COM1 by doing this:

1. Have a On Error routine in COM2
2. In COM1 have a procedure that will rollback transactions
(i don't know if your using ADO)
3. Call that routine in COM2, if COM2 fails.

Code in COM1:

Public Sub procRollbackTrans
'put your code here
End Sub

Code in COM2:
Dim m_objCOM1 As COM1

Private Sub Class_Initialize()
On Error GoTo ErrHandler
Set m_objCOM1 = New COM1
'put your code here
Exit Sub
ErrHandler:
m_objCOM1.procRollbackTrans
End Sub

 
If you are using MTS, above explanation by VBvader is
not usuafull. Because you should not use initialize events for MTS components.
Instead you can use MTS transaction using transactionobject.

in COM1

public sub call1()
dim obj as objectcontext
dim objcom2 as com2.class
obj = getobjectcontext()
set com2 = obj.createinstance("com2.class")
on error goto errl
'--- some operation

com2.call2()
obj.setcomplete
errl:
obj.setAbort
end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top