pass information to/from Web Browser Control

D

Dave

I am trying to create a custom form that has a web page on it using the Web
Browser Control. I am able to pass information to the web page using query
strings and reloading the page when something on the form is changed that
should change what the embedded web page should display. I would also like to
be able to pass information back from the web control back to the form. Does
anyone know if this is possible?

I have tried using mypage.controlname.webpagefieldname but that says the
object is not valid.
 
S

Sue Mosher [MVP-Outlook]

To pass information from the web control back to the form, you'd need to parse the page that the control is displaying using IE methods (or raw HTML) or put Outlook automation code behind the web page, which would be likely to encounter 2-3 different layers of security that might block what you want to do. See http://www.outlookcode.com/article.aspx?ID=38 for information on Outlook property and custom form control syntax.
 
D

Dave

Thanks for the reply.

So would the code to parse the page be code in the Outlook form?

I have looked at the page you linked to and thought maybe I could do
something the following but it did not work.
Set MyPage = Item.GetInspector.ModifiedFormPages("Resource Scheduling")
Set objControl = objPage.Controls("WebBrowser1")
msgbox objControl.confroom ' confroom is the name of the
field on the web form

How would I got about parsing the page the control is displaying?
 
S

Sue Mosher [MVP-Outlook]

Add a reference to the Web Browser control (C:\WINDOWS\system32\ieframe.dll) to Outlook VBA, and you'll be able to see in the object browser (F2), under SHDocVw, all the properties and the methods of that control. That includes a Document property, which if a web page is shown, will return an HTMLDocument object whose elements can be parsed with IE programming methods. At that point, you're into the realm of IE programming, which is largely my area of expertise (and the scope of this forum). Docs start at http://msdn2.microsoft.com/en-us/library/aa752043.aspx

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
D

Dave

When designing a form the script editor is just vbscript so is it possible to
add a reference? It appears to me that when designing a form classes can not
be added to the object browser.

Is this covered at all in your Outlook 2007 programming book?
 
S

Sue Mosher [MVP-Outlook]

VBScript does not support references. That's why I suggested using the object browser in Outlook VBA to explore.

I do not cover the Web Browser control in my book, but do cover basic Outlook form control and property syntax extensively.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
D

Dave

So I have just gotten back to this project and am still having issues. Does
anyone have example code of a form that pulls information from a Web Browser
control for use on the Outlook form? From my rookie abilities I have come up
with the following code which is inside a button click event just attempting
to get it to echo back the value of my field:

Set MyPage = Item.GetInspector.ModifiedFormPages("MyPage")
Set objControl = MyPage.Controls("MyWebControl")
Set resvalue = objControl.GetProperty("MyFieldOnWebPage",displayvalue)
msgbox displayvalue

When I click the button I get a message saying "Wrong number of arguments or
invalid property assignment: 'objControl.GetProperty'".

I can't find any sample code of doing this type of thing.

Thank you,
Dave
 
H

Hollis Paul

Set resvalue = objControl.GetProperty("MyFieldOnWebPage",displayvalue)
msgbox displayvalue
I infer that you are trying to move the display value of
"MyFieldOnWebPage" to the variable resvalue. In which case, you would
not use a Set command, but just the equal sign. Then you would say
msgbox = resvalue

It would be a good idea to do an int directive to reserve namespace for
the variable.

Finally, you will want to have defined an Outlook property in your
folder to receive the value from the variable, say "myOLvar".

Set myOLprop = Item.CustomProperties.Find("myOLvar")
myOLprop = resvalue

Then do an Item close and save.

I have generated the above code from very faint memory traces so be sure
to go to Sue's site, www.outlookcode.com, and search for the article on
syntax to get the real scoop on how to write that code.

Now, the error you are seeing is probably due to the MsgBox command
format, which has a lot of parameters, depending upon if you want to
collect a response of yes, no, Maybe the sky will fall, etc. You want
to look that up with help from the code editor.
 
D

Dave

Paul,
Thank you for the reply on this.

You are correct on not using the Set command to get the value and that helps
some. The standard way of getting the value of the properties do not work
though as I'm trying to get the value of a control on an ASP.net web page
that is embedded in the form as a WebBrowser Control.

I have proven that I'm getting the control properly as I can display the
type of page, the url being displayed and the name of the page. What I'm
having issues with is how to reference the control on that page through the
script editor. Sue mentioned using the object explorer but I can't get that
to show the elements of the specific browser.

Any other pointers? They all seem to get me a step closer...
 
H

Hollis Paul

Any other pointers? They all seem to get me a step closer...
You need to set a reference to the Object Model or library of control
you are using. You do that by opening the VBA gui for Outlook and
click Tools-->Set References. Finding the specific library is tricky
and I never learned a good way of doing that. For me, it is a trial
and error process.
 
K

Keith Trangmar

I'm actually trying to achieve something similar to you albeit in Visual
FoxPro, and one of Sue's earlier replies has provided the solution
(thanks Sue!).

You can reference the content of a field in the form via

oBrowser.document.forms(0).inputfieldname.value

where oBrowser is the instance of the web browser control. If there's
more than one form on the page then you'll have to figure out which one
you need to interrogate. You could even do it by cycling through them
all starting from 0 until oBrowser.document.forms(counter) returns NULL,
but you'd have to check whether each form actually contained an object
with the requisite name, but I'm afraid my VB is as limited as my
knowledge of the IE document model so I can't offer you any example code
for that.

Regards,

Keith Trangmar
 
D

Dave

Thank you very much to all that responded. The syntax Keith has below worked
for me. I'm sure I should have been able to figure that out from the VBA
pieces Sue pointed out but I was getting hungup on just trying to reference
document as it's own property.

I can now move on to completing my project.

Your help is very much appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top