E
Eugene via AccessMonster.com
Here's an approach that I have developed to capture navigation events from
the webbrowser control.
If someone can provide a more elegant solution, please share!
1) Create a blank MS Access database
2) Create a form
3) Create a WebBrowser control on the form
4) Put the following text into the form's code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
Me.WB.Width = Me.WindowWidth
Me.WB.Height = Me.WindowHeight
MeWB.Navigate Application.CurrentProject.Path & "\webif.htm"
End Sub
Private Sub WB_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags
As Variant, TargetFrameName As Variant, PostData As Variant, Headers As
Variant, Cancel As Boolean)
If InStr(URL, "#") > 0 Then
Select Case UCase(Mid(URL, InStr(URL, "#") + 1))
Case "RELOAD"
Me.WB.Navigate Application.CurrentProject.Path & "\webif.htm"
Case "MSGBOX"
MsgBox "Hello, World!"
Case "INPUTBOX"
q = InputBox("What is your name?", "Question", "")
Case "CLOSEDB"
DoCmd.Quit acQuitSaveAll
End Select
End If
End Sub
5) Save the form
6) Copy the code below into a blank text file and save as "webif.htm". Place
the file in the same folder as the database you have created.
7) Open the form and test all links.
________________________________________________________________________________
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-
1252">
<meta http-equiv="Content-Language" content="en-us">
<title>
WebBrowser-to-VBA interface sample
</title></head>
<body topmargin="2" leftmargin="2" rightmargin="2" bottommargin="2"
marginwidth="0" marginheight="0">
<a name="CloseDB"></a>
<a name="MsgBox"></a>
<a name="Reload"></a>
<a name="InputBox"></a>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr><td colspan="2">
<font color="#006000"><b>WebBrowser-to-VBA interface
sample</b></font></td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
This sample provides an approach with which VBA can control
events happening on
the WebBrowser control places on a form in MS Access (also
applicable to MS
Excel).</td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
Everything is being done with the links in HTML document loaded
into WebBrowser
control. In WebBrowser control, WB_BeforeNavigate2 and
WB_NavigateComplete2
events are used.</td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
Sample links:</td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
1) <a href="#CloseDB">Close the database</a></td></tr>
<tr><td colspan="2">
2) <a href="#MsgBox">Show a message box</a></td></tr>
<tr><td colspan="2">
3) <a href="#Reload">Reload this page</a></td></tr>
<tr><td colspan="2">
4) <a href="#InputBox">Ask for a value</a></td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
Steps to accomplish this demo:</td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
1) Create a blank MS Access database<br>
</td></tr>
<tr><td colspan="2">
2) Create a form<br>
</td></tr>
<tr><td colspan="2">
3) Create a WebBrowser control on the form<br>
</td></tr>
<tr><td colspan="2">
4) Open VBA (Alt+F11) and place the following text into the
form's code:<br>
</td></tr>
<tr><td width=20>
</td><td>
<font face="Courier New">Private Sub Form_Open(Cancel As Integer)
<br>
DoCmd.Maximize<br>
Me.WB.Width = Me.WindowWidth<br>
Me.WB.Height = Me.WindowHeight<br>
MeWB.Navigate Application.CurrentProject.Path &
"\webif.htm"<br>
End Sub<br>
<br>
Private Sub WB_BeforeNavigate2(ByVal pDisp As Object, URL As
Variant, Flags As
Variant, TargetFrameName As Variant, PostData As Variant,
Headers As Variant,
Cancel As Boolean)<br>
Me.Caption = URL<br>
If InStr(URL, "#" > 0 Then<br>
nbsp; Select Case UCase(Mid(URL, InStr
(URL, "#" + 1))<br>
Case
"RELOAD"<br>
Me.WB.Navigate Application.CurrentProject.Path & "\
webif.htm"<br>
Case
"MSGBOX"<br>
MsgBox
"Hello, World!"<br>
Case
"INPUTBOX"<br>
q =
InputBox("What is your name?", "Question",
""<br>
Case
"CLOSEDB"<br>
DoCmd.Quit
acQuitSaveAll<br>
End Select<br>
End If<br>
End Sub</font></td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
5) Save the form and open it</td></tr>
<tr><td colspan="2">
</td></tr>
</table>
</body>
</html>
the webbrowser control.
If someone can provide a more elegant solution, please share!
1) Create a blank MS Access database
2) Create a form
3) Create a WebBrowser control on the form
4) Put the following text into the form's code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
Me.WB.Width = Me.WindowWidth
Me.WB.Height = Me.WindowHeight
MeWB.Navigate Application.CurrentProject.Path & "\webif.htm"
End Sub
Private Sub WB_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags
As Variant, TargetFrameName As Variant, PostData As Variant, Headers As
Variant, Cancel As Boolean)
If InStr(URL, "#") > 0 Then
Select Case UCase(Mid(URL, InStr(URL, "#") + 1))
Case "RELOAD"
Me.WB.Navigate Application.CurrentProject.Path & "\webif.htm"
Case "MSGBOX"
MsgBox "Hello, World!"
Case "INPUTBOX"
q = InputBox("What is your name?", "Question", "")
Case "CLOSEDB"
DoCmd.Quit acQuitSaveAll
End Select
End If
End Sub
5) Save the form
6) Copy the code below into a blank text file and save as "webif.htm". Place
the file in the same folder as the database you have created.
7) Open the form and test all links.
________________________________________________________________________________
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-
1252">
<meta http-equiv="Content-Language" content="en-us">
<title>
WebBrowser-to-VBA interface sample
</title></head>
<body topmargin="2" leftmargin="2" rightmargin="2" bottommargin="2"
marginwidth="0" marginheight="0">
<a name="CloseDB"></a>
<a name="MsgBox"></a>
<a name="Reload"></a>
<a name="InputBox"></a>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr><td colspan="2">
<font color="#006000"><b>WebBrowser-to-VBA interface
sample</b></font></td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
This sample provides an approach with which VBA can control
events happening on
the WebBrowser control places on a form in MS Access (also
applicable to MS
Excel).</td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
Everything is being done with the links in HTML document loaded
into WebBrowser
control. In WebBrowser control, WB_BeforeNavigate2 and
WB_NavigateComplete2
events are used.</td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
Sample links:</td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
1) <a href="#CloseDB">Close the database</a></td></tr>
<tr><td colspan="2">
2) <a href="#MsgBox">Show a message box</a></td></tr>
<tr><td colspan="2">
3) <a href="#Reload">Reload this page</a></td></tr>
<tr><td colspan="2">
4) <a href="#InputBox">Ask for a value</a></td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
Steps to accomplish this demo:</td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
1) Create a blank MS Access database<br>
</td></tr>
<tr><td colspan="2">
2) Create a form<br>
</td></tr>
<tr><td colspan="2">
3) Create a WebBrowser control on the form<br>
</td></tr>
<tr><td colspan="2">
4) Open VBA (Alt+F11) and place the following text into the
form's code:<br>
</td></tr>
<tr><td width=20>
</td><td>
<font face="Courier New">Private Sub Form_Open(Cancel As Integer)
<br>
DoCmd.Maximize<br>
Me.WB.Width = Me.WindowWidth<br>
Me.WB.Height = Me.WindowHeight<br>
MeWB.Navigate Application.CurrentProject.Path &
"\webif.htm"<br>
End Sub<br>
<br>
Private Sub WB_BeforeNavigate2(ByVal pDisp As Object, URL As
Variant, Flags As
Variant, TargetFrameName As Variant, PostData As Variant,
Headers As Variant,
Cancel As Boolean)<br>
Me.Caption = URL<br>
If InStr(URL, "#" > 0 Then<br>
nbsp; Select Case UCase(Mid(URL, InStr
(URL, "#" + 1))<br>
Case
"RELOAD"<br>
Me.WB.Navigate Application.CurrentProject.Path & "\
webif.htm"<br>
Case
"MSGBOX"<br>
MsgBox
"Hello, World!"<br>
Case
"INPUTBOX"<br>
q =
InputBox("What is your name?", "Question",
""<br>
Case
"CLOSEDB"<br>
DoCmd.Quit
acQuitSaveAll<br>
End Select<br>
End If<br>
End Sub</font></td></tr>
<tr><td colspan="2">
</td></tr>
<tr><td colspan="2">
5) Save the form and open it</td></tr>
<tr><td colspan="2">
</td></tr>
</table>
</body>
</html>