I've been battling for ages to get an event raised in .NET 2 to fire in VB6. After a lot of searching, and huffing and puffing I finally found this resource which was the only example which seemed to do what I needed to do, i.e. raise an event AND call a method for the same COM component.

The code in C# is as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace ComEventTest2
{
public delegate void TestEventHandler();

#region interface defining events
/// This is the interface for the Event
/// It will be used with ComSourceInterfaces for the class definition
[ComVisible(true)]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IClass1_Event
{
void Test();
}
#endregion

#region interface normal stuff
/// This is the interface for other methods etc which are to be exposed to the
/// consuming program
[ComVisible(true)]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IClass1_Code
{
void DoSomething();
}
#endregion

#region class

/// This is the class
/// It implements IClass1_Code
/// It uses ComSourceInterfaces to specify which events are valid
/// It sets ClassInterface to be None to prevent any other methods from
/// being displayed in the consuming program
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[ComSourceInterfaces(typeof(IClass1_Event))]
public class Class1 : IClass1_Code
{
public Class1()
{
}

public event TestEventHandler Test;

public void DoSomething()
{
Test();
}
}
#endregion
}

The code within VB is as follows:

'Define the object
Dim WithEvents test As ComEventTest2.Class1

Private Sub Form_Load()

'initialise the objects
Set test = New ComEventTest2.Class1

'call the DoSomething method (this fires the event)
test.DoSomething

End Sub

Private Sub test_Test()

'Let us know that the event was fired and captured ok
MsgBox "The event has fired"

End Sub

Now to get it to work for real against VBA in an Access interface. Wish me luck!