browseEmbed Quickstart

Use this page to walk through an initial setup of the bemb within your Access project.

Package Contents

The v0.5.0.0 package (download from this page) contains objects that cover three categories: Registry stuff for initial setup, some demo stuff for ChartJS and the core objects required to use bemb.

Bemb Core Objects

  • BembSubform: just needs to be present, you don’t need to do anything with it
  • BembEventHandler: needs to be present but needs to be imported, do not copy/paste module content (see below) – you don’t need to do anything with this either
  • BembObject: this is the main class (and only one) that you’ll be programming with

Bemb Registry Modules

Two optional mobules that help you get the registry settings correct to make good use of the web browser control.

  • Registry: some quick WMI work to check/set registry values
  • BembRegistry: functions specific to registry for the bemb project

ChartJS Demo Objects

  • Two demo ChartJS tables that hold info for the chart series
  • Two demo ChartJS queries that aggregate the table data for the chart series
  • Two demo ChartJS subforms that allow you to edit the table data and see changes in the bemb chart
  • A demo ChartJS form that you will want to open to see the demo in action
  • A demo ChartJS Popup form that will open when you click a value set in the chart

Setting the Registry for IE11 Emulation

The default version of IE used by the Web Browser control is – I believe – IE7.  This is no good for any sort of modern project, and you’ll want to change that.  Setting the emulation mode involves an edit to the Registry.  This can be done under the HKCU (CurrentUser) hive, meaning that no administrative privileges are required (it can also be done under HKLM (Local Machine), which affects all users on the computer, but this requires admin privileges and may not be desirable for distribution/installation reasons).

The download package contains two modules that will help with this.  See the notes in the section below for details on how to use them.  Alternatively, you can set this manually.  More in-depth detail can be found on the bemb Documentation page.

Importing bemb into your Access Project

  1. If you have not set up your registry yet, either import the Registry and BembRegistry modules into your application, or run them directly from the demo package (either way is fine, it just needs to run once per Windows login). Run the following code: SetIEEmulationMode IEEmulation11
  2. Import the following objects from the v0.5.0.0 Access file into your project:
    • BembSubform
    • BembEventHandler
    • BembObject

    It is important that the BembEventHandler is imported from an existing VBA project or from a .cls file (that was previously exported from a VBA project or has been modified as required). This is because the class requires a default method property to be set which cannot be set from within Access/VBA: it must be set as part of a text output and imported. See “Setting the Default Method” in the bemb Documentation for details on how to do this manually.

  3. Ensure that the VBA References includes the “Microsoft Internet Controls” library.  This is added by default when you first put a Web Browser Control onto any form in your project, but may not be present when you import the objects from the bemb package (for those cautious of extra references, know that this one is rather benign and is pretty much guaranteed to be present for any Access 2010 or later installation of Access, as it’s associated with the native Web Browser control).
  4. Create a blank form that will contain your chart. This can have other unrelated objects on it, it’s not restricted to the chart only.
  5. Add a subform control to your form and size accordingly.  This will hold your chart.  Give it a reasonable name (subChart perhaps).  You may want to set the Border to Transparent.
  6. Save the form and open the VBE.  You want to add code to the form’s Load and Unload event.  This will set up your bemb object that you’ll interact with to display and handle your chart.  Additionally, you’ll need a WithEvents BembObject variable declared at module level:

    The bemb.Init procedure takes a reference to the subform that your chart will go in, and takes a link to the html file that will be hosted.

  7. Create a procedure stub for the Initialized() event of the BembObject.  In here you’ll set your snippets path and set up your JavaScript event handlers.

    Adding an event handler requires the jQuery selector (eg, element id or classname, in this case the #cavnas id from our HTML), the name of the JavaScript event (click, for this example), the object whose method will be called (this form), and the name of the procedure of that object that will be called (the “bembEvent_ChartClick” for demo purposes). Additionally, any JavaScript code that you might want to run before VBA receives the events can be specified as well. In this case, we use the Snippets feature to tell it to take the values of the points that were clicked and make them available to us.

    Of particular note is the .LastData property of the bemb object. This holds whatever was last posted from the JavaScript. By default, this is either the event object (if the last action was receiving an event we subscribed to) or the return value of a JavaScript function that we called. In this case, by using the ability to run some custom script after the event is raised but before it’s passed to VBA, we override the value that will be returned from the default JavaScript event object to our specified point values that from the chart.

  8. Congrats, your basic setup is done.  The rest is up to you, however you’d like to use it.  See the ChartJS demo for some details, as well as the bemb Documentation page.

Mark of the Web for your Custom Pages

While the demo html file includes it already, part of the puzzle to allow JavaScript and ActiveX content to run unhindered from the webpage in the hosted control is an IE “feature” called Mark Of The Web.  MOTW is a special comment placed at the top portion of the HTML document, under the DOCTYPE but before the opening html element:

The (0022) portion of the MOTW line is the number of characters in the URL that follows. The URL itself doesn’t much matter. On the whole, this asserts that the file was downloaded from the web and thus bypasses the restrictions that IE places on ActiveX content running from local machines (whether or not that’s well thought out is a matter of which I’ll keep my opinions to myself…)