Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable is undefined

Status
Not open for further replies.

Medwyn

Technical User
Apr 15, 2001
9
NZ
I am having trouble with a function which takes the data given to it and then opens a new window and displays the data. The function works while it is by itself, but when I add it to the Head of the HTML with the rest of the Sub's it throws up the error Variable is undefined.

The function is as follows:

Function WriteLinetoWin(data1)
Set OpenNewWin = Window.open("","NewWindow", "toolbar=yes,titlebar=yes,height=400,width= 700,resizable=yes,left=20,top=20")
OpenNewWin.document.write(&quot;<html><head><title>Test Data</title></head><body>&quot;)
OpenNewWin.document.write(&quot;<h3><p align=&quot;&quot;center&quot;&quot;>Test Data<br>&quot;)
OpenNewWin.document.write(Data1)
OpenNewWin.document.write(&quot;</body></html>&quot;)
End Function

Is there something I am overlooking?

Thanx

Medwyn
 
try adding this line directly under your sub declaration:

dim OpenNewWin

and look to the very top of the page -- you will see the declaration, 'option explicit'

It's vb's way of saying, &quot;The programmer is going to have to declare any variables he/she will use&quot;

If you don't include that line, then you are allowed to use variables without declaring them, but I wouldn't suggest doing that. It can make debugging a real nightmare.

Just use option explicit, and be sure to 'dim'ension all variables before you use them.

good luck! :)
Paul Prewett
 
Thanks for the suggestion but now I get an error stating

Object required 'OpenNewWin'

this is on the line:

OpenNewWin.document.write(&quot;<html><head><title>Test Data</title></head><body>&quot;)

Any sugguestions?

Medwyn

 
Also a new blank window is opened.

a about:blank window

Medwyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top