[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Focus on Second IE Window to call functions via VB Script

Posted on 2012-09-19
5
Medium Priority
?
1,101 Views
Last Modified: 2012-09-23
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?
0
Comment
Question by:Kds4evr
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:Nico Bontenbal
ID: 38420770
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
 

Author Comment

by:Kds4evr
ID: 38422484
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
 
LVL 22

Accepted Solution

by:
Nico Bontenbal earned 2000 total points
ID: 38426329
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
 

Author Comment

by:Kds4evr
ID: 38426641
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
 

Author Comment

by:Kds4evr
ID: 38426768
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question