0% found this document useful (0 votes)
107 views16 pages

Browseembed - Html5/Javascript For Your Access Projects: Browseembed Home Page Quickstart Guide Documentation

The document discusses the development of browseEmbed, a tool for creating HTML5/JavaScript charts in Access projects. It was created because the native charting in Access is outdated and using Excel for charting has drawbacks. The tool allows embedding a web browser control on Access forms and loading local HTML pages with JavaScript charts. This overcomes limitations by allowing JavaScript to communicate events and data to VBA code through global variables and a "bridge" element. The tool uses standard web technologies without third-party dependencies, enabling interactive charts and drill-down functionality within Access applications.

Uploaded by

leonard1971
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views16 pages

Browseembed - Html5/Javascript For Your Access Projects: Browseembed Home Page Quickstart Guide Documentation

The document discusses the development of browseEmbed, a tool for creating HTML5/JavaScript charts in Access projects. It was created because the native charting in Access is outdated and using Excel for charting has drawbacks. The tool allows embedding a web browser control on Access forms and loading local HTML pages with JavaScript charts. This overcomes limitations by allowing JavaScript to communicate events and data to VBA code through global variables and a "bridge" element. The tool uses standard web technologies without third-party dependencies, enabling interactive charts and drill-down functionality within Access applications.

Uploaded by

leonard1971
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

browseEmbed – HTML5/JavaScript for your Access


projects
browseEmbed Home Page
QuickStart Guide
Documentation

Where did it come from?


I’ve always hated trying to handle charting in Access. The Chart objects that Access provides
are ancient and clunky and nobody really uses them because of that, so our next common
option is to automate Excel for charting capabilities. This is much better than the native
charting, but still has a number of drawbacks. For one, it requires Excel to be installed
(usually not an issue, but sometimes can be), it requires a fair bit of automation code, setting
up template Excel files, etc. If you want the charts shown within your Access forms or
dashboards, you have to snap a picture of the chart object from excel, save it, and load the
image into Access. Again, not a big deal – it’s a very feasible solution that’s been the practice
of many for a long time, but still leaves something to be desired. Besides the slight flicker in
loading the images, there’s no interactivity. Even if you output data to Excel and then open
the file, Excel interactivity on charts isn’t the best either.

Not for the first time, I wondered how awesome it would be to make use of some JavaScript
solutions. What if you could throw a web browser control on your Access form, load up a
local html page and have the two of them communicate with each other? Sounds great, but a
major PITA (anyone that’s tried any sort of heavy automation with the Web Browser control
is likely to agree on the PITA part… that thing is a whiny little bitch.)

Not just for charting either… think custom nav bars, embedded applets. All sorts of stuff. If
only there were some way to transfer information and events from JavaScript back to VBA…
then you could do all sorts of stuff. Mainly though, I was interested in the ability to a)
mouseover chart values and get feedback on it, and b) click on a chart and drill down to the
data behind it. Naturally, using Access to handle this drilldown info is highly ideal.

So, over the period of some months, I was able to not only come up with a way to do so, but
also to make it stable and relatively easy to use (it wouldn’t be worth much if it took 10 times
as long to embed a chart than it would to automate it from Excel).

I came up with the way to do it a few weeks before the MVP Summit late last year, and
slapped together a real quick demo and a terrible unprepared (and thus terrible) presentation
to some of the MVPs. Despite the terrible presentation that I gave, there seemed to be a fair
bit of interest, and many of those whose opinions I highly respect have indicated that this is
definitely a Good Thing.

What makes it work?


One of the best things about this, IMO, is that it’s all native. No 3rd party tools, no DLLs, no
ActiveX controls (as long as you don’t count the native Web Browser Control as an ActiveX,
even though it actually is). No oddball references – there’s one reference, but it’s benign and
added by default if you use the native web browser control anyway, so of little consequence I
think. The only real ticker is that we need to make a registry edit to tell the web browser
control to run in a different emulation mode (by default it uses IE7, I tell it to use
IE11). However, even this worked out well… thanks to fellow MVP Tom van Stiphout, who
(shortly before I pulled together all the pieces for this project) determined how to use the
HKCU hive to get this functionality, meaning that no administrative privileges are required,
ultimately meaning that we can implement this pretty easily with a bit of code in the VBA
project.

Working with the Web Browser Control (particularly, the DOM and JS within) requires three
basic hurdles to be crossed. First, we must be able to manage the Emulation Mode
(check). Then, we have to use the MOTW crap so IE doesn’t restrict certain page processing
from local pages (check). And finally, we need some way to both execute JavaScript from
VBA (check) and just as importantly, subscribe to JavaScript/DOM events from
VBA. Check.

IE Emulation Mode

So this one’s fairly straightforward: add the following key if it doesn’t already exist:

HKCU\Software\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

Then add a DWORD value called “msaccess.exe” for the key using a value of 0x2edf (11999)
for IE 11 emulation. (the package I put together on the bemb download page has a registry
module that uses WMI to check/create registry keys and values, and a BembRegistry module
where you can call one function that will set this as required).

Mark Of The Web

I’m not even sure this is strictly required – I believe it only effects ActiveX controls
embedded in local webpages, not JavaScript itself, but it’s so easy to do that I’ve just included
it anyway. Basically, if you’re hosting a page from your local machine (which is what I had
always intended when creating the bemb project), you need a special comment line after the
DOCTYPE but before the opening HTML element:

1<!DOCTYPE html>
2<!-- saved from URL:(0022)http://www.dymeng.com -->
3<html>

That just tells IE that it’s ok to run content on this page. Good to go on that end.

Event Subscribing

Ok, so that’s relatively common stuff and no big deal. What about event handling? Can we
really have our VBA project receive JavaScript events? Turns out, we can.

I found this old MSDN post explaining how to do just that (which is when all of the pieces
finally clicked and I thought holy shit, this might actually work!). Actually, I think offhand
that it was part of the VB6 documentation using the ActiveX web browser control, but it
works perfectly well with the native control in Access 2010+. Basically, you declare an
object with a default method and pass that object to the specific part of the hosted DOM, and
when that event is raised in the DOM, it calls the VBA object’s default method and viola – an
extremely basic means of communication between JavaScript and VBA.

Unfortunately, this in itself isn’t quite enough. It has some major restrictions and is not the
silver bullet, but it does open the doors. For one, the event you subscribe to here has to be of
public scope in the DOM and can’t be referenced by a literal string value. This is a major
issue, because most events that we’d want to subscribe to we’d have to use literal strings to
specify.

Then there’s a matter of getting any sort of usable information from the event. There’s no
support for passing information via parameters to our VBA object, and realistically, events do
us little good without some information to go with it.

Not to be deterred, I figured that if I could put together some custom JavaScript – a bit of a
framework that could be attached to a loaded DOM – there’s a good chance that I can work
around these severe limitations and get good information flow between JS and VBA. We can
read a globally scoped JavaScript variable from VBA easily enough… the correct command
against the DOM will do that. We can execute JavaScript code from VBA against the
DOM. Just a matter of writing the script and sending it through the correct method of the
browser control. So, we can execute code, read variables, receive events, and we can tag on
JavaScript to the DOM after the page is initially loaded… hmmm….

What If:
 Have a local html page that calls up the script required to handle a charting library
 Load that into a web browser control
 Attached a little framework script to the DOM of that loaded page. This would…
 Create a dedicated global variable in JS that we can use to transfer information from
JS to VBA
 Create a single hidden element in the DOM that we would use as an “event bridge” –
eg, link the VBA to some event of this element, and when some specific JS event
occurs, have JS raise this event bridge element’s event so VBA gets notified. Before
that happens, write some event info to the previously created global var so VBA can
read it. Then we’ve got one single event that VBA subscribes to and we leave it up to
JavaScript code to determine which events we really want.

My initial thoughts were a bit more loose than that, but after a long round of trial and error
that’s more or less what it amounted to.

Let’s look at how the Event process works in the practical sense:

 The VBA project keeps a collection of events that we’ve told it to subscribe to. Each
event is internally given an ID value.
 When we tell it to subscribe to the event, we pass a jQuery selector and an event
name. This is pretty awesome because we can subscribe to every click event with
class “btn” if we want.
 The “framework” file that gets added to the DOM on initialization has JS code to
handle this request. Here’s what that code does:
 It runs an AddEventListener call to specify the event that we’ve told it to against the
selectors that we’ve told it to. Additionally, it passes along a function (because JS is
pretty awesome and can pass functions as arguments) that will run when this event is
raised.
 This function that’s attached to the AddEventListener call basically says “hey, let our
framework code know that this event was subscribed to by the VBA project”
 At which point, the event ID, event object (and a few other important things) are
written to global variables.
 Next, the JS code looks at that hidden event bridge element that was created on
initialization and fires the click event of that element.
 That click event is received in VBA. Essentially this means to the VBA project “hey,
some event we subscribed to was just fired”
 The VBA project then reads the global vars from the JS framework, getting the
EventID, which it cross references to the VBA collection of subscribed events.
 It finds the correct event for the given ID and proceeds to call the code we specified
when we originally set up the event.

Awesome. Still needs a bit of work though… primarily, converting data from JS objects onto
VBA strings can be a bit of a pain (VBA can only read global variables as strings, not
objects). We could use JSON stringification, but that still leaves a lot of parsing required on
the VBA end, which is kinda ugly. For example, let’s say you have a chart Click event that
would get serialized to a string and that whole JSON string would be read into VBA. You’d
then have to parse out that entire object to find the piece of information you want (such as:
what series/point was clicked?).
What would be a lot easier would be to define a custom JS function that could run after the
event is raised in JS, but before it’s returned to VBA. So I set this up also… the
AddEventHandler method of the VBA BembObject class takes an optional JS script to
run. Thus, in the case of clicking a chart, we can effectively say “take the event object, get
the points that were clicked, write them into the main data var”, so when the VBA event is
received, we just need to check the .LastData property of the BembObject and see whatever
we wanted to write there.

Awesome.

Does it Work?
Actually, yes. Quick well in fact. After months of tinkering with it and shelving it and
tinkering with it some more, I found a scenario to use it for a client and said well, let’s see
how this goes.

The scenario was a monitoring system for some automated server processes that run every 10
minutes or so… I wanted to get a realtime charted display of various information (run times
for the process, count of errors, etc). Each process writes to a SQL Azure event log, and this
monitor would aggregate that data into hourly chunks and show me the aggregates for each
hour. If I hover over an item on the chart, it’d tell me how many successful processes ran,
how many errors there were, what the max runtime of the process was for the hour, and if I
click on a point, it’d open a detail form in Access that drills down to the processes that ran in
that hour giving me further information.

So, with the framework already worked up and used fairly intensively in personal tests, I
imported a couple of objects, set up a few template functions for charting the info, extracted
the data from the queries and stuffed the values into a string and passed them on to the
chart. This went so well that I was absolutely tickled pink (a rare event for me… few things
really get me excited). The best part? Besides this awesome functionality that we’ve never
really had before… it took less than an hour to implement. Less than an hour to set up an
interactive drilldown chart within Access? I couldn’t have done the Excel setup for
embedded chart snapshots in less than an hour, let alone this (even if it could be done via
Excel). And that hour included having to google some things like how to format the
mouseover tooltips and such. That includes putting it on the client’s server and running the
registry code (which worked great, btw).

That, my friends, is a success story. (the implementation was similar to that in the v0.5 demo
that uses ChartJS, except I went with Highcharts instead).

Where to go from here?


Good question. While my primary intent with this whole thing was to get really good
charting capability (which it does very well with), there’s a whole slew of other things it could
be used for. Navigation bars will probably be my next toy project for it, but the implications
are huge…

Currently, the framework is designed to well handle local pages that have been created with
the intent to embed. Even so, the html page can be created in isolation, as if it were
standalone, so we don’t have to worry about whether it will actually be embedded… the
initialization procedures take care of appending the framework script and wiring up the
events, so theoretically this could be against ANY html, local or out on the web.

One thing that I definitely want to revisit is the current handling for jQuery. As of now
(v0.5), the framework assumes that jQuery will be present and makes use of that existing
jQuery reference to handle what needs handling. This is fine for hosting your own local pages
to be embedded, because we’ll have complete control over that page and can easily just make
sure we have some reasonably recent jQuery version, but if we were to want to use this
against webpages found “in the wild”, we’d need better support for that. Another area that
could use significant improvement is error handling. Interestingly enough, if a VBA
procedure is called as the result of a JS event and that VBA code doesn’t include an error
handler, any errors raised by VBA will be propagated back through JS and can be handled
there. Cool… not sure what practical use that might be, but neat anyway. On the other end,
we can wrap pertinent JS code in try/catch blocks and elegantly handle errors and report
messages/error info back to VBA via the main data transfer var. The current version has little
of this set up (actually it has little error handling at all set up), but the options are there to
expand upon, ultimately making it easier to troubleshoot JS errors that pop up as “script
errors” with absolutely no helpful information.

Another tool I’m likely to try out is Firebug Lite, which can apparently be embedded into any
browser on demand, so that would be of significant help in debugging as well. Again though,
I haven’t done anything on this end quite yet.

All in all, I’m quite happy with how this project came together. Hopefully someone else can
find it useful as well!

Cheers,
– jack

Overview
browseEmbed (bemb) is a project piloted by Access MVP Jack Leach of Dymeng Services
that enables the communication between your VBA projects and HTML5/JavaScript via the
Access 2010+ native Web Browser control.

While the techniques listed below are native to Access/VBA and allow the functionality
required, in order to make good use of the VBA/JS integration, a bit of a framework needs to
be put together. This framework is being actively developed using native Access/VBA and
will allow developers to quickly and easily integrate bemb projects into their applications.

(to subscribe to updates to the bemb project, click here)

Use Cases
Essentially, the bemb project allows for any HTML utility to be integrated into your VBA
project. A few example use cases are as follows:
 Rich interactive dashboards using JavaScript Charting libraries
 Advanced navigation controls without trying to fight against the current with Access
and VBA
 HTML5/JavaScript applets for just about anything you can think of (like this Math
problem widget, as one example)

The abundance of web based utilities is nearly boundless, and the being able to integrate
JavaScript events into our Access/VBA applications allow us to make good use of them in
more ways than I care to try and enumerate here!

Three Pillars
In order to have an embedded HTML5/JavaScript solution that’s viable as a “real” solution,
there’s a few things that need to happen. First, we need to be able to manage the IE Emulation
Mode of the Web Browser control so it uses a decently recent version of IE, rather than its
default emulation of IE7. Secondly, we need to be sure that the web content can run
unhindered when loaded directly from our computer instead of from the web – a common
problem with IE, and finally we need a way to subscribe to HTML element events in our
VBA projects.

IE 11 Emulation w/ the Web Browser Control

The Web Browser control by default runs in IE7 emulation mode, which is typically
insufficient for tasks of any substantial means. Usually, we’ll want to use IE11 Emulation
mode instead. This involves the setting of some registry values, as fellow Access MVP Daniel
Pineault explains in this link (furthermore, use the HKCU root instead of HKLM so users
(and your code) don’t require UAC to make the change – thanks to Access MVP Tom van
Stiphout for working that out).

A demo video of this process can be found here: Registry Settings

Unhindered JavaScript/ActiveX from the Local Machine

If you plan to use this to read HTML from the local machine, IE may complain a bit,
depending on the content contained, or just plain restrict certain required functionality. To
manage this, use MOTW as explained here:

 Mark of the Web


 Internet Explorer Local Machine Zone Lockdown

Subscribing to JavaScript Events from VBA

Here it is, the last piece of the tripod. The following MSDN article explains how to create a
class module that can be used as an event handler for an HTML element:

Web Browser Control – Handling Events in Visual Basic Applications


Do note that this link refers to VB6, not VBA, and in order to work in VBA requires a bit of a
trick to set the default method of a class. Chip Pearson explains here: Setting the Default
Member of a Class

Resources

Latest Version: v0.5.0.0


2015-02-27

Download v0.5.0.0

bemb.v0.5.0.0.zip
QuickStart Guide
Documentation
Blog Post

(ask questions in the blog post’s Comment section, or at UtterAccess.com)

bemb QuickStart (v0.5.0.0)

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 modules 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 (has a function to set up the registry values required for the web browser
control via the Registry module, details below)

ChartJS Demo Objects

 Two demoChartJS tables that hold info for the chart series
 Two demoChartJS queries that aggregate the table data for the chart series
 Two demoChartJS subforms that allow you to edit the table data and see the changes in the
bemb chart
 a demoChartJS form that you will want to open to see the demo in action.
 a demoChartJSPopup 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 see the demo video here
for a walkthrough of how to do it 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:
o BembSubform
o BembEventHandler
o 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:

1 Option Compare Database

2 Option Explicit

4 Private WithEvents bemb As BembObject

6 Private Sub Form_Load()

7 Set bemb = New BembObject

9 ' this helps keep scrollbars from showing up in the chart area

10 bemb.AllowScroll = False

11

12 bemb.Init Me.SubChart, CurrentProject.Path & "\bemb\demoChartJS\charting.html"

13End Sub

14

15Private Sub Form_Unload()

16 If Not bemb Is Nothing Then Set bemb = Nothing

17End Sub

7. 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.
8. 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.

1 Private Sub bemb_Initialized()

2 bemb.SnippetsPath = CurrentProject.Path & "\bemb\snippets.js"

4 AddChartClickEventHandler

5 End Sub
6

7 Private Sub AddCheckClickEventHandler()

8 Dim script As String

9 script = bemb.GetSnippet("ChartClickHandlerSnippet")

10 bemb.AddEventHandler "#canvas", "click", Me, "bembEvent_ChartClick", script

11End Sub

12

13Private Sub bembEvent_ChartClick()

14 DoCmd.OpenForm "demoChartJSPopup", , , , , _

15 acDialog, "The values of the clicked point were " & bemb.LastData

16End Sub

9. 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.
10. 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.
11. 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:

1<!DOCTYPE html>

2<!-- saved from url=(0022)http://www.dymeng.com/ -->


3<html> ...

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…)

BembObject public properties and methods POGLAVLJE


Properties

Property Accessibility Description


Sets the AllowScroll property of the Web Browser
control. This helps in making sure scrollbars don’t appear
AllowScroll Read/Write inside your hosted object. Alternatively, use a small
margin on the html’s body element. Must be set before
Initializing.
Returns the HTMLDocument object (equivalent to
Document ReadOnly WebBrowserControl.Object.Document). Applicable
only after Initialization.
Returns the version of jQuery used in the hosted page
jQueryNativeVersion Read Only (currently all hosted pages require any fairly recent
version of jQuery). Applicable only after Initialization.
Gets the last data posted to the framework’s BembData
variable. This is typically filled with: event information
LastData Read Only for subscribed events, function return values for evaluated
functions or custom data specified by your custom
JavaScript. Applicable only after Initialization.
Gets or Sets the path to the Snippets file to be used. Can
SnippetsPath Read/Write
be used before or after Initialization.
Gets or Sets the start qualifier to be used for the Snippets
SnippetStartQualifier Read/Write file. Default /// StartSnippet: Can be used before or
after Initialization.

Methods (click a Method Name for detailed syntax)

Return
Method Arguments Description
Type
Selector, EventName, Adds an event listener to the
ReceivingObject, specified element(s) and calls the
ReceivingMethod, specified object.method when the
AddEventHandler N/A
Optional Snippet, JavaScript event is raised. Use the
Optional LastData property to get
OmitQuoteWrap application information on the
Return
Method Arguments Description
Type
event.
Runs the specified code (and
CodeToRun, Optional
Eval String optional function to run after the
PostFunction
code) and returns the value
Do Not Use! This exists as a
EventReceived N/A N/A requirement for the internal Event
Handler. Leave this alone…
ExecScript N/A None Executes the specified script
Returns the contents of the specified
Snippet, or ZLS if not present. See
SnippetsPath and
GetSnippet String SnippetName SnippetStartQualifier
properties, as well as the Snippets
section of this documentation for
more information.
Initializes the object. Takes the
subform that will serve as the object
SubformContainer,
Init N/A container and the URL to the page
URL
to display (current version doesn’t
support page navigating).
Loads the contents of a text file into
LoadScriptFileToString String FilePath
a string. Useful for loading files.

Events

Event Arguments Description


Raised after the object and framework are fully initialized. Use this
Initialized None event to set up your event handlers and any other tasks that might
require the hosted page to be present.

jQuery Integration
Currently (as of v0.5.0.0), jQuery handling is rudimentary but required. The hosted page
*must* include some jQuery library of reasonable recency (figure on jQuery 1.7+ being ok, I
haven’t fully tested how far back we can go though).
jQuery is required for the event listening and a few other internals of the bemb Framework.
The bemb framework creates its own jQuery object called $_bemb. This reference is created
by setting it to the jQuery object itself, which is why it’s crucial that jQuery exists in the core
html/javascript.

Future plans do involve better support for jQuery, but are currently not implemented.
However, you can access the version of jQuery being used through the bemb’s
jQueryNativeVersion property.

Snippets
Snippets are a feature of the BembObject that allows you to store bits and pieces of JavaScript
code in a dedicated file, without having it loaded into the DOM. Typically it would be used
for JavaScript code pieces that would be pulled into VBA before passing them as some of the
various Bemb methods.

This serves two purposes: first, it allows us to have “loose” JavaScript code that isn’t loaded
into the DOM, so we can store bits and pieces without worrying about negative effects on the
DOM, and secondly – if you’ve ever tried to write code for another language inside a different
language… yea, not much fun. This lets us write the JavaScript snippets as if it were actually
JavaScript instead of having to mess around trying to escape quotes and build ugly strings of
JavaScript from within VBA.

How it Works
Quite simply, the Snippets feature points to a file, there’s a specific string used to denote the
start of a Snippet (by default: /// SnippetStart: [snippetNameHere]). Everything after
that start line, up to the next found start line or the EOF, is returned.

You can change the start line by setting the SnippetStartQualifier property, and you can
change the snippets file path by using the SnippetsPath property. Use the GetSnippet()
method to get the snippet you need.

Example from ChartJS demo

1 /// StartSnippet: WindowResizedHandlerSnippet


2
3 Canvas.width = window.innerWidth;
4 Canvas.height = window.innerHeight;
5
6 /// StartSnippet: ChartClickHandlerSnippet
7
8 var points = window.myLine.getPointsAtEvent(event);
9 bembData = points[0].value + ', ' + points[1].value;
10
11/// StartSnippet: RefreshChartDataBuild
12
13refreshChart({
14 labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'],
15 datasets: [{
16 label: 'Dataset 1 Name',
17 fillColor: 'rgba(220,220,220,0.2)',
18 strokeColor: 'rgba(220,220,220,1)',
19 pointStrokeColor: '#fff',
20 pointHighlightFill: '#fff',
21 pointHighlightStroke: 'rgba(220,220,220,1)',
22 data: [|DATASET1|]
23 }, {
24 label: 'Dataset 2 Name',
25 fillColor: 'rgba(151,187,205,0.2)',
26 strokeColor: 'rgba(151,187,205,1)',
27 pointStrokeColor: '#fff',
28 pointHighlightFill: '#fff',
29 pointHighlightStroke: 'rgba(151,187,205,1)',
30 data: [|DATASET2|]
31 }]
32}, {
33 responsive: true,
34 bezierCurve: true,
35 pointHitDetectionRadius: 5,
36 pointDotRadius: 5,
37 datasetStrokeWidth: 1,
38 bezierCurveTension: 0.4
39});

Registry Information
Registry Instruction Video

browseEmbed Registry Setting Tutorial.mp4


The bemb download package contains two
modules that can help with setting up the registry for IE11 Emulation Mode. See the
QuickStart page for details.

Notes on setting the Registry values:

 Key: HKCUSoftwareMicrosoftInternet
ExplorerMainFeatureControlBROWSER_FEATURE_EMULATION
 Value: DWORD “msaccess.exe” 11999 (0x2edf or 2edf)
 The Registry setting can be made under either HKLM or HKCU. HKCU is preferred
in that it doesn’t require admin privileges (many thanks to Tom van Stiphout for
working this out). The BembRegistry module uses the HKCU hive and is intended as
an easy way to run a client location for manual setup.
 Distribution should be relatively easy, in terms of Registry requirements anyway. One
could either use their own little install routine that makes use of the code that’s in the
BembRegistry module, or this value could be set as part of an installer’s script.
 Important! This emulation mode is required to be set for the msaccess.exe executable,
which means that any Access programs that may run on this computer will use the
emulation mode set here. This shouldn’t generally be a problem, but is definitely
worth keeping in mind. In a worst case scenario, you may want to include code to
remove/reset the value on your application shutdown. In an absolute worst case
scenario, you may want to create an executable wrapper which calls your Access
program and enter the Registry value under that executable name (note: I have not
tried this and am not sure it will work).

You might also like