Webbrowser control source from VBA string and .HMTL file (1 Viewer)

AVILLAGE

New member
Local time
Today, 13:03
Joined
Dec 23, 2017
Messages
4
I’m trying to set a Access form web browser (wbmap2) control source by creating a text string and then using the property setting wbmap2.ControlSource = textstring. This is the web browser that comes with Access 2010, NOT the ActiVex variety. I want to use Bing Map scriptcontrol V8, so I have loaded some HTML code from their SDK site.
I first built a long text string in VBA and tried .navigate, but this only works with activex variety of the control.... and with even with the Activex the string didn't work, even though it seemed to be the code specified by Bing Maps (SDK V8, load map asyncHTML)

So I then saved the code in a file, OpenMap.html.
When I open that file in IE 11 (or Chrome) it opens as it should, but when I use this file asthe web browser control source , it throws a script error.

I first initialize the browser when the form opens, then try and set the control source when the document completes. At that point there is a script error that points to a problem with code in the saved file- it seems to be in the URL bit.
This may an issue for HMTL developers, but I can’t see why a file that works OK when loaded directly to a browser then doesn’t work as a control source. Is it a security setting in Access / the webbrowser control?
VBA code:
Code:
Private Sub Form_Load()

wbmap2.ControlSource = " about:blank"
Me.Refresh
End Sub


Private Sub wbmap2_DocumentComplete(ByVal pDisp As Object, URL As Variant)

'wbmap2.ControlSource = "=("" [bing maps normal web address]"")"   'works OK
wbmap2.ControlSource = "=""[file location on my computer]"""
Me.Refresh
End Sub

Can't seem to post the HTML code as I'm a newbie to this game...

Ideas / experience gratefully received...web and web browser controls are new territory for me!
 

isladogs

MVP / VIP
Local time
Today, 13:03
Joined
Jan 14, 2017
Messages
18,186
As I suggested in my response to your first post, I think you will find Google maps API easier to work with

I suggest you look at this sample database which links postcodes to Google maps
https://www.access-programmers.co.uk/forums/showthread.php?t=295378

Even if you want to stick with Bing, the code may be worth looking at

The full version of this app will be available next month here:
http://www.mendipdatasystems.co.uk/uk-postal-address-finder/4594138311
As well as postcodes, that links maps to geo-coordinates or full addresses

So I then saved the code in a file, OpenMap.html.
When I open that file in IE 11 (or Chrome) it opens as it should, but when I use this file as the web browser control source , it throws a script error.

There is an issue linking some online maps to web browser controls in recent versions of Access / Windows. I don't know whether it also affects Bing maps.
This issue occurs because the web browser still expects to use Internet Explorer 7 after all these years.
The fix is a registry hack which I described here:
https://www.access-programmers.co.uk/forums/showthread.php?t=297244
 

jleach

Registered User.
Local time
Today, 09:03
Joined
Jan 4, 2012
Messages
308
It might be part of IE's ridiculous MOTW "feature", which prevents certain actions if the file is served locally (why anyone thought this was a good idea, I'll never know):

https://msdn.microsoft.com/en-ca/library/ms537628(v=vs.85).aspx?f=255&MSPPError=-2147217396

After the DOCTYPE line, put the following:

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

... and see if it works any better.

Screenshot 2017-12-24 15.03.28.png
 

AVILLAGE

New member
Local time
Today, 13:03
Joined
Dec 23, 2017
Messages
4
Thanks for the help ridders & Jleach- much appreciated! the immediate problem was related to the default IE browser version (7) when I have IE11... registry key change sorted that. I also added the MOTW line just in case.
Well now I can load a file saved on my machine into the standard webbrowser using ControlSource value set to the file name.
So the next trick was to write the file from my VBA programme when the form loads (eventually I want to give it the co-ordinates to centre the map). I used the standard .write to file method ... which didn't work because it left the quote marks in the file, so then I used .print. Made the file OK, which looks identical in every respect to the Bing Maps syntax I downloaded. So here's the rub... the downloaded syntax works fine in IE and as a ControlSource for my webbrowser:
The created syntax in the new file works fine in IE11, but NOT as a control source for my web browser. It just leaves the control blank.
So I have tried using the Activex version of the web browser and 'navigate2' the written file- no luck (same thing download version OK, .print version nothing). I've tried saving the syntax as a variable and navigating2 (activex) but this throws syntax error from the HTML code (which I suspect is not an error since that code works OK in a web browser).

So today's conundrum is 'why doesn't the web browser control like a file created in VBA as a ControlSource when the same file work in a web browser? I could post the VBA code, but I'm not sure that's the problem.. seems to be something to do with reading files created in VBA.

Looking around, this issue of creating dynamic HTML code VB /VBA and getting it to work in a web browser controls (standard or Activex) seems to have been an on-going issue for years (some of the threads I'm looking at are over a decade old). Just wondering if MicroSoft has a current solution that works for Access 2010 and Windows 7 (32 bit).
Many thanks!
 

Users who are viewing this thread

Top Bottom