Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I help maintain an MFC application that uses Access 2003/2007 for its reporting. It's a system we're trying to change - Access is not very flexible and our "hosting" of Access inside MFC is a bit haphazard.</p> <p>I wasn't a first party to the design of the hosting architecture and why things were implemented in certain ways, but here's a short outline of two difficulties we have with Access in our application:</p> <p><strong>Only a full Access installation registers the <code>Access.Application</code> OLE Automation interface</strong>. If you can guarantee that your users will have a full installation of Access then this won't apply to you (<code>CLSIDFromProgID</code> followed by a <code>CoCreateInstance</code> will get you an automation interface), but if you have to get an <code>Access.Application</code> object for the Access Runtime then there's some extra plumbing to be done. You need to start <code>msaccess.exe</code> and <a href="http://support.microsoft.com/kb/238610" rel="nofollow">mess around with <code>GetActiveObject</code> and <code>Sleep</code> until you get find an instance of the interface</a>. There's <a href="http://support.microsoft.com/kb/145707" rel="nofollow">KB145707</a> which shows the two ways to connect, albeit in VBA.</p> <p><strong>Access is not designed to be embedded in another application</strong>. There's no <a href="http://support.microsoft.com/kb/311546" rel="nofollow"><code>Excel.Sheet</code></a> equivalent for Access reports. You can see this in your CodeProject sample - it renders a report to an intermediate <code>.html</code> file and then uses an embedded web browser control to display the report.</p> <p>Our application does The Wrong Thing (TM) here and fiddles with the Access application's window style, parent and position and makes it look like there's a report inside our application but it's just a visual sleight of hand. While <a href="http://blogs.msdn.com/b/oldnewthing/archive/2011/03/31/10147981.aspx" rel="nofollow">there's nothing wrong with having parent/child windows from different processes</a>, in this case it leaves us with us some undesired behaviour.</p> <ol> <li><p>We use a custom Office Ribbon, and because Access 2007's ribbon is part of the window frame the user can drag Access "out" of our app. </p></li> <li><p>When a process terminates it gives up any "foreground focus" it had. When <code>msaccess.exe</code> closes because the user has closed a report our app ends up at the bottom of the window z-order (due to the way we've parented the Access window).</p></li> </ol> <p>I think you should look at actual reporting libraries, and compare them to the effort you'll need to go to integrate Access into your application.</p> <ul> <li><p><a href="http://www.microsoft.com/download/en/details.aspx?id=6442" rel="nofollow">Microsoft Report Viewer</a> is a lightweight yet powerful reporting library. It uses .NET, but you can use a proxy application to host the control. From above, it's valid to have parent/child windows from different processes. If you can get your application to C++/CLI, it's even easier with <a href="http://msdn.microsoft.com/en-us/library/8z4d86s2.aspx" rel="nofollow"><code>CWinFormsControl</code></a>.</p></li> <li><p><a href="http://www.businessobjects.com/jump/xi/crvs2010/default.asp" rel="nofollow">SAP Crystal Reports</a> is also free, but it's not as lightweight as Report Viewer.</p></li> </ul> <p>If you absolutely have to use Access, I'd personally steer away from using the automation interfaces and use an <a href="http://office.microsoft.com/en-us/access-help/about-startup-options-HP005188724.aspx" rel="nofollow"><code>AutoExec</code></a> macro with the <a href="http://support.microsoft.com/kb/209207" rel="nofollow"><code>/cmd</code></a> switch to describe which report I want rendered and where to render it to. <code>AutoExec</code> would kick in, render the report and close Access (there's an example of the technique <a href="http://support.microsoft.com/kb/207672" rel="nofollow">here</a>). Once the output file is created, you can take that and embed it in your application. A couple of suggestions:</p> <ol> <li><p>If your reports are simple then stick with the <code>.html</code> and web browser example from the CodeProject article.</p></li> <li><p>If your reports have complex formatting you could output the report as a <code>.snp</code> (Snapshot) file and then display it in your application (the <a href="http://support.microsoft.com/kb/175274" rel="nofollow">Access Snapshot Viewer</a> is embeddable - the PROGID is <code>snpvw.Snapshot Viewer Control.1</code>).</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload