[AccessD] Interface Callback Class Questions.

Robert Gracie Subscriptions at servicexp.com
Wed Jan 28 20:04:22 CST 2004


Ken,

 Thank you very much for the help.

RE: Yep your correct, you can't reference an "un-compiled" reference in
an mde, which does change my approach a bit. The object however remains
the same..

I implemented your solution below, and noted a few problems.

The report fires, however none of the events (Close) are being hooked. 

I can run the report once, any attempt to run the report again fails on
"RemoteReportClose mrRpt.Name" ERROR Number 2467....... Object or
property... either does not exist or is closed...... 

I tried it in both A2K and AXP Formats, same results


Do I need to hook the opening report to the events in the CReportHost
class internally of the opening report, such as on the OnOpen event? I'm
new to the "DEEP" Programming method so I could be way off base.....

What do you think?


Do you do any teaching? You are a good teacher.....

Thanks For the Help Ken...

Robert Gracie

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Ken Ismert
Sent: Wednesday, January 28, 2004 3:58 PM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Interface Callback Class Questions.



Robert,

To make this work, you need a public object interface or type library
that both projects (your Host and Remote) can agree on.

You could define an Interface class in the Remote db, set its Instancing
property as 2 - PublicNotCreatable, allowing you to use objects that
implement this interface in both the host and remote projects.

But that is not strictly necessary, as you already have the Access
public type library, which defines the Report interface, which both
projects obviously understand.

So, you could do it this way:

1. Add a Public Report Open function in a Remote module that returns an
Access.Report
   You also need a matching Report Close function.
2. Add a Report class in the Host to sink events from the remote report.
3. Add code in a Host module to open and close the report.

As I only have A2K, I can't answer the question as to whether the Report
interface is forward compatible between A2K and AXP. I tend to think so.
If not, you will be forced to use another approach, likely one involving
interfaces.

I do have a question for you: I found I couldn't reference a remote mdb
from a host mde. I had to make the remote mdb into an mde, and reference
it in the host, before I could successfully make the host mde. How did
you get around this?

-Ken

Here is the code that I wrote to test this functionality:

1. Report Open/Close functions in a Remote module:
==================================================
Public Sub RemoteReportClose(sReportName As String)
    On Error GoTo HandleErr
    DoCmd.Close acReport, sReportName
    Exit Sub
HandleErr:
    Err.Raise Number:=Err.Number, _
        Description:=Err.Description, _
        Source:="modMain.RemoteReportClose" & vbCrLf & Err.Source
    Exit Sub
End Sub

Public Function RemoteReportOpen(sReportName As String) As Access.Report
    On Error GoTo HandleErr
    ' Init
    Set RemoteReportOpen = Nothing
    ' Open Report
    DoCmd.OpenReport sReportName, acViewPreview
    ' Return
    Set RemoteReportOpen = Application.Reports(sReportName)
    Exit Function
HandleErr:
    Err.Raise Number:=Err.Number, _
        Description:=Err.Description, _
        Source:="modMain.RemoteReportOpen" & vbCrLf & Err.Source
    Exit Function
End Function

2. The CReportHost class in the Host:
=======================================
Option Compare Database
Option Explicit

Private Const pcsEventStub As String = "[Event Procedure]"

Private WithEvents mrRpt As Access.Report

Property Get IsOpen() As Boolean
    IsOpen = Not (mrRpt Is Nothing)
End Property

Property Get Name() As String
    Name = ""
    If mrRpt Is Nothing Then Exit Sub
    Name = mrRpt.Name
End Property

Public Sub CloseRemoteReport()
    On Error GoTo HandleErr
    ' Close Report if Open
    If mrRpt Is Nothing Then Exit Sub
    RemoteReportClose mrRpt.Name
    Exit Sub
HandleErr:
    Err.Raise Number:=Err.Number, _
        Description:=Err.Description, _
        Source:="CReportHost.CloseRemoteReport" & vbCrLf & Err.Source
    Exit Sub
End Sub

Public Sub OpenRemoteReport(ReportName As String)
    On Error GoTo HandleErr
    ' Open Report
    Set mrRpt = RemoteReportOpen(ReportName)
    ' Hook Close Event
    mrRpt.OnClose = pcsEventStub
    Exit Sub
HandleErr:
    Err.Raise Number:=Err.Number, _
        Description:=Err.Description, _
        Source:="CReportHost.OpenRemoteReport" & vbCrLf & Err.Source
    Exit Sub
End Sub

Private Sub Class_Terminate()
    On Error Resume Next
    CloseRemoteReport
End Sub

Private Sub mrRpt_Close()
    MsgBox "Report " & mrRpt.Name & " closed!"
    Set mrRpt = Nothing
End Sub

3. Module-level Code in Host:
=============================
Public grReportHost As CReportHost

' Call this routine to open a remote report
Public Sub OpenRemoteReport(sReportName As String)
    On Error GoTo HandleErr
    ' Close current Report, if any
    If Not (grReportHost Is Nothing) Then
        If grReportHost.IsOpen Then
            grReportHost.CloseRemoteReport
        End If
    End If
    ' Remake Host Object
    Set grReportHost = New CReportHost
    ' Open Report
    grReportHost.OpenRemoteReport sReportName
    Exit Sub
HandleErr:
    MsgBox "Error: " & Err.Number & vbCrLf _
        & Err.Description & vbCrLf _
        & "modMain.OpenRemoteReport" & vbCrLf & Err.Source
    Exit Sub
End Sub


-----Original Message-----
From: Robert Gracie [mailto:Subscriptions at servicexp.com]
Sent: Tuesday, January 27, 2004 6:29 AM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Interface Callback Class Questions.



Hello All

AK2 mde referencing A2K mdb

Objective:
  To open a report in a (host is an mde referenced to the .mdb)
referenced .mdb and have all the events for a given report fire inside
the host mde.  I can do this for a report located inside the mde,
however I can seem to figure out how to get the report inside the .mdb
to see the class in the mde, as circular references are not permitted in
access.

Question:
 I was thinking that an Interface callback would be an option. So is it
possible to use an interface callback across a referenced db to
accomplish my objective? Any examples...?


Thanks
Robert Gracie



_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list