Hi All,

We are beginning some testing of automating Access from a .Net client. We
are using Office XP and the Office XP PIA's.

We can open the database and show a form no problem but we are now
attempting to hook the forms Close event.

We have tried this in C# and it raises a run-time COM exception when
attempting to attach the event handler. In VB.Net we can use AddHandler
without problems but the event handler is never called when the form is
closed.

The code is straightforward, but I have attached it below anyway.

Thanks All,

Mal

Imports Microsoft.Office.Interop.Access
Imports System.Runtime.InteropServices

Public Class AccessThingy
    Public Sub TestConnection()

        Dim testDB As Application = New ApplicationClass()
        Dim oForm As Form
        testDB.Visible = True
        testDB.OpenCurrentDatabase("C:\TEMP\DatabaseTesting\Simple.mdb")

        Try
            testDB.DoCmd.OpenForm("frmApplication")
            oForm = testDB.Forms("frmApplication")
            oForm.Visible = True
            oForm.SetFocus()
            AddHandler oForm.Close, AddressOf(CloseMethod)
        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine(ex.Message)
        End Try
    End Sub

    Private Sub CloseMethod()
        Console.WriteLine("Form closed!")
    End Sub

    Public Shared Sub Main()
        Dim o As New AccessThingy
        o.TestConnection()
        Console.ReadLine()
    End Sub

End Class

===================================
This list is hosted by DevelopMentor�  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to