Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 14th, 2005, 01:50 PM
Registered User
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Controlling InternetExplorer


I am writing some code to fill in a form on a web page which I don't have control of. I'm using something along the lines of:

Dim IE as InternetExplorer

Set IE = new InternetExplorer

With IE
  .Navigate "blah"
  .Document.formname.elementname.value = "blah"

Trouble is the form loads into a new window after the navigate line so the questions are...

1. how do I set an internetexplorer object to reference this new window so that I can start entering on the form?

2. once i've done this how do I "click" the submit button?

Any help much appreciated
Old March 15th, 2005, 07:20 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

you can trap the new window creation and provide your own IE object, then you can control the new window using the same code you already posted. Here's a simple example:
1. Declare 2 form level IE objects, be sure to declare them WithEvents (I'll assume they're called g_ie and g_ie2...)
2. Create the first IE object (g_ie) and call its Navigate function
using the code you posted already
3. because you declared g_ie WithEvents, you'll have a placeholder for a procedure named g_ie_NewWindow2. The default parameter ppDisp is the object that will be used to create the new window, so this is where g_ie2 comes in - add code here to supply your own IE object (g_ie2) instead of the default ppDisp. Like this:
Private Sub g_ie_NewWindow2(ppDisp As Object, Cancel As Boolean)

    Set g_ie2 = New InternetExplorer
    Set ppDisp = g_ie2
    Cancel = False

End Sub
4. now the new window can be referenced using your variable g_ie2, so you can just fill in the form fields using g_ie2.Document and call g_ie2.Document.formname.submitname.submit to submit the form

Old March 15th, 2005, 07:22 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

Correction, you don't need the submitname to submit the form, so
should just be

Similar Threads
Thread Thread Starter Forum Replies Last Post
"controlling mechanism" using SmptMail ? garaxan ASP.NET 2.0 Professional 1 September 3rd, 2007 08:16 AM
How do I obtain a SHDocVw.InternetExplorer cschene VB.NET 2 December 8th, 2006 07:29 PM
Controlling a Windows Service sajid08 C# 1 October 30th, 2006 04:53 AM
Silent SHDocVw.InternetExplorer Jenda Pro VB 6 0 August 31st, 2004 12:22 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.