WebBrowser.Navigate: works in button click, not on form open RRS feed

  • Question

  • Hi.  I have a web browser control on a form that, when the form is opened, I want to display the contents of a file folder. I can't.  To identify the problem, I simplified my testing to just this:  a form with a web browser control and a button.  The code I am try to run for my test (my actual business intent is more complex) is simply this line of code with nothing else in the procedure:

    Me!WebBrowser3.Navigate "C:\Users\WAB\Documents\_My Access Apps\"

    This single line of code --- with no other code before or after --- will not work in the form's OnOpen event:  the browser displays an HTML page that says "The address is not valid."  Surprisingly, when I right-click on the browser control and select "Back", it then displays my file folder correctly --- even though I had closed and reopened the form just before running the test so there shouldn't be a previous page content it could go back to. Unfortunately, simply adding a GoBack to my code is not a solution.  That only causes an error when the form is next reopened.

    More surprisingly, this same simple line of code does work perfectly in the OnClick event of a button on the form, again with no other code before or after it. In my test, I deleted my OnOpen event code and closed and reopened the form before testing the code in the button, so the two tests were independent.  I am baffled.

    I've encountered this problem on two different computers today using Access 2013 (one at work and one at home, both test databases being created from scratch) and on another computer using Access 2010 (also at home and also from scratch).  It makes no difference what folder path I use.  I've changed none of the default properties of the form or webbrowser control other than inserting code for the form's OnOpen event.  I've spent two hours searching the web before posting and have not found anyone who has had the same problem. 

    Thanks in advance for any help you can provide.

    • Edited by Will_B Tuesday, July 7, 2015 4:46 AM
    Tuesday, July 7, 2015 4:32 AM

All replies

  • After considerably more research on the web and experimentation with other properties and methods of the webbrowswer control set by various approaches (with similarly disappointing results), I'm now convinced this is a shortcoming of how the webbrowser control was designed.  I've therefore altered my approach for my business project and will have all browser-related code run from buttons and control frames.  There is therefore no need to reply to this positing.

    Thanks to the 20+ people you viewed this posting and, perhaps, replicated my experiment themselves.
    Tuesday, July 7, 2015 10:26 PM
  • Hi Will_B

    Did you tried another event instead of Form_Open ?

    For instance Load or Activate ?

    Perahaps Form_Open is too soon for the control... just a guess...


    Wednesday, July 8, 2015 6:20 PM