Use this page to walk through an initial setup of the bemb within your Access project.
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
- 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
- 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
- Import the following objects from the v0.5.0.0 Access file into your project:
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.
- 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).
- 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.
- 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.
- 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:
Visual Basic1234567891011121314151617Option Compare DatabaseOption ExplicitPrivate WithEvents bemb As BembObjectPrivate Sub Form_Load()Set bemb = New BembObject' this helps keep scrollbars from showing up in the chart areabemb.AllowScroll = Falsebemb.Init Me.SubChart, CurrentProject.Path & "\bemb\demoChartJS\charting.html"End SubPrivate Sub Form_Unload()If Not bemb Is Nothing Then Set bemb = NothingEnd Sub
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.
Visual Basic12345678910111213141516Private Sub bemb_Initialized()bemb.SnippetsPath = CurrentProject.Path & "\bemb\snippets.js"AddChartClickEventHandlerEnd SubPrivate Sub AddCheckClickEventHandler()Dim script As Stringscript = bemb.GetSnippet("ChartClickHandlerSnippet")bemb.AddEventHandler "#canvas", "click", Me, "bembEvent_ChartClick", scriptEnd SubPrivate Sub bembEvent_ChartClick()DoCmd.OpenForm "demoChartJSPopup", , , , , _acDialog, "The values of the clicked point were " & bemb.LastDataEnd Sub
- 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
<!-- saved from url=(0022)http://www.dymeng.com/ -->
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…)