Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

COM Component

COM Component

COM Component

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

RE: COM Component

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
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
End Sub

RE: COM Component

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

end sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close