Focus on Second IE Window to call functions via VB Script

Hello Expert,

 I have been spinning my wheels on a problem for several days involving calling functions in IE6 using Vb Script from Access. Here is my code so far:

Set oIE = CreateObject("InternetExplorer.Application")
oIE.Silent = True
oIE.Visible = True
oIE.Navigate "webaddress - secure site"
    While oIE.Busy: DoEvents: Wend
    Sleep 2000
oIE.Document.Forms("Main").elements("_ctl0_tbxUserName").Value = DLookup("TPXID", "tblUser", "[LANID]='" & SQLUserName & "'")
oIE.Document.Forms("Main").elements("_ctl0_tbxPassword").Value = DLookup("[Employee ID]", "tblUser", "[LANID]='" & SQLUserName & "'")
oIE.Document.Forms("Main").elements("_ctl0:btnLogin").Click
    While oIE.Busy: DoEvents: Wend
    Sleep 1000
oIE.Navigate "webaddressreporting"
    While oIE.Busy: DoEvents: Wend
    Sleep 1000
oIE.Navigate "webaddresswebquery"
    While oIE.Busy: DoEvents: Wend
    Sleep 2000
Set oIE2 = CreateObject("InternetExplorer.Application", oIE.Document.frames(0).execScript("AssessmentChange()", "JavaScript"))
    While oIE2.Busy: DoEvents: Wend
    Sleep 2000
Call oIE2.Document.Forms("src").execScript("return ReturnAll();", "Javascript")

Open in new window


The issue I am having is on the AssessmentChange() function, a seperate window is called by the function. I have looked for a way to set focus on the new window. The new window displays some criteria to the original window (oIE) to move forward with a webquery. I tired to call an oIE2 window using the function as the string, but it will not allow me to call any functions in the oIE2 window now. The message:

Method "document" of object "IWebBroswer2" failed.

Any thoughts on how I can set the focus on the new window so that I can call the functions I need?
Kds4evrAsked:
Who is Participating?
 
Nico BontenbalCommented:
The 'go' function is on the child window right? It seems to call the 'RemoteAssessment' function on the main window. Parameters are a ('75559027|80213072'), b ('Pre Claims Ownership Midterm') and obj ("fWizForm1.assessmentName"). Did you try calling the RemoteAssessment function on the main window directly?

But the xtremevbtalk code should work also. Change line 18 of your original script to:
oIE.Document.frames(0).execScript("AssessmentChange()", "JavaScript")

Open in new window

Below that use the xtremevbtalk sample to get a reference to the new IE window. Then continue with line 21 of your original script.
0
 
Nico BontenbalCommented:
It it possible to check what the ReturnAll code on the childwindow does to the main window and just execute that on the main window (oIE). Or maybe the AssessmentChange() function returns a reference to the child window. If it doesn't you might be able to execute the contents of the AssessmentChange() function as a script and modify this slightly so it does return a reference to the child window.

On this page http://msdn.microsoft.com/en-us/library/ie/ms535873(v=vs.85).aspx the second to last example says you can use frames to list the child windows. Maybe you can give that a try as well.

I don't understand the line
Set oIE2 = CreateObject("InternetExplorer.Application", oIE.Document.frames(0).execScript("AssessmentChange()", "JavaScript"))

Open in new window

You call CreateObject with 2 parameters. This second parameter is the name of the server, this is used for Remote Automation. I don't see what this has to do with your problem.

You might be able to get a reference to the child window using this technique:
http://www.xtremevbtalk.com/archive/index.php/t-247343.html
It's the code in the post of 12-10-2005, 10:41 AM.
0
 
Kds4evrAuthor Commented:
Hey Nicobo,

I appreciate your response. xtremevbtalk was able to provide me with the path the child window opens with. I am able to use the AppActivate to set the focus on the childWindow. This is where I run into a wall. When I try to send a command via vbscript to control the window it will not reference the child window.

I imagine is it due to the oIE reference still pointing to the parentWindow. The confusing code above was my attempt to tell vb to point to the childWindow to run the function I need in that window. It obviously does not work. That being said, to your other question about calling the function from the childWindow to the parentWindow without the need for the child . . . I would love to do that.

As you can see with this vbscript, the parentWindow just references a hyperlink to the childWIndow. Easy enough.
function AssessmentChange() {
window.open("../Common/assessment_selection.asp?field=fWizForm1.assessmentName","selectassessments","scrollbars=yes,resizable=yes,toolbar=no,status=yes,menubar=no,screenX=100,screenY=100");

Open in new window



This part is where I have an issue. I have tried all sorts of approaches to get this function to run and return the value to the parent window. It will always return the same value for what I am using for.
function go(a,b) {
			var obj;

			obj="fWizForm1.assessmentName";

			window.opener.RemoteAssessment(a,b,obj);


				window.close();

Open in new window


And here is the onclick event in the childWindow:
a class="link" id='a75559027|80213072' onMouseOver="JavaScript:ShowToolTip('Pre Claims Ownership Midterm','7555902780213072','PROG1\\lcram','','18-Nov-2011');"  onMouseOut="JavaScript:HideToolTip();" class=intcellslink" href="#" onClick="javascript:go('75559027|80213072','Pre Claims Ownership Midterm');return false;">

Open in new window

0
 
Kds4evrAuthor Commented:
Hey Nicobo,

I like the idea of just calling the RemoteAssessment function directly and setting the parameters vs having to open to open the second window. I have tried to call the function but keep getting an error:

Runtime error -2147352319(80020101)
Could not complete the operation due to error 80020101

Here is what I have. I am sure it is a syntax error at this point:
Call oIE.Document.frames(0).execScript("RemoteAssessment('75559027|80213072','Pre Claims Ownership Midterm','fwizForm1.assessmentName')", "JavaScript")

Open in new window


Any ideas?
0
 
Kds4evrAuthor Commented:
Nevermind! It was a syntax error and it works perfectly now!

Thank You Nicobo

Call oIE.Document.frames(0).execScript("RemoteAssessment(75559027|80213072,'Pre Claims Ownership Midterm','fWizForm1.assessmentName')", "JavaScript")

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.