How to open a document (local/network file or web page) from MS Access
When developing Access database applications, you may want to open a document (a file on your local or network drive, or a web page) by the user or automatically opening the document in a background process coded in VBA. For example, after processing customer orders, Access opens web browser that displays sales and orders information for this month in HTML web page format.
There are three ways to open a document by Access - using FollowHyperlink method, Shell function, or Navigate method.
1. Using FollowHyperlink method
The FollowHyperlink Method of Access Application object opens a document or Web page specified by a hyperlink address.
For a web page, it's always opened by the default web browser of your computer. If you want the web page to be opened in a web browser other than the default one, use the second method that uses Shell function.
For a file on your local computer or network, it'll be opened by the default program of your PC.
To test this function, use the code below. It opens geeksengine.com website in your default web browser.
2. Using Shell function
Shell function of MS Access runs an executable program so if we specify the EXE file of a web browser (e.g. Firefox.exe), the web page can be opened by that browser, or if the document is a file on your local computer or network, the web browser will prompt you to choose a program to open the file.
To test this function, use the code below. It opens geeksengine.com website in Firefox.
3. Using the Navigate method of an Internet Explorer instance
The third method opens a document in Internet Explorer only. It creates an instance of Internet Explorer, then uses the Navigate method to open a web page or file.
You can open a URL or a file by passing the appropriate path to the Navigate method.
Setting the Visible property to False will hide Internet Explorer window. This can be useful when opening a document that can't be opened directly by Internet Explorer, such as opening a Microsoft Word document, because an IE window is not opened at all. Regardless of what you specify in the Visible property, if IE can't open the document, you'll be prompted to open or save the document anyway. See screenshot below.
For more about the CreateObject Method, refer to Microsoft page here.
Here is the third method.
To test this function, use the code below.
Copyright © 2013 GeeksEngine.com. All Rights Reserved.
This website is hosted by LunarPages.
No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.