Hi All,
I have a bit of code that I am having a problem w/. I have a little hta that will let a user select their location, then type in the printer name, and then have some vb code run to add the printer connection. I have it set to where if the user just clicks of without typing anything it will error, but if they type in the name of a non-existant printer it just gives a runtime error and i don't know how to make it so it will display the error i want them to see.
thanks in advance
<HEAD>
<TITLE>Set Up Printer By Location</TITLE>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Set Up Printer By Location"
BORDER="Dialog"
CAPTION="Yes"
SCROLL="NO"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="Yes"
WINDOWSTATE="normal">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">
option explicit
on error resume next
dim pc, net, netprint, wmisvc, printobj, printadd, printcol, printer, printset
dim loc, printsrv, print, printname, ements
pc = "."
set net = createobject("wscript.network")
Sub Window_OnLoad
Window.Site.Focus
End Sub
Sub btn01_OnClick
ements = Window.Site.SelectedIndex
loc = Window.Site.Options(ements).Text
print = BasicTextBox.Value
Select Case loc
Case "location 1"
Case "location 2"
Case "location 3"
Case "location 4"
printsrv = "\\location4_server\"
print = BasicTextBox.Value
printset = printsrv & print
msgbox printset
if print = "" then
msgbox "You have not typed in a correct printer name" &_
vbcrlf &_
vbcrlf &_
"please try again",64, "Printer setup error"
window.close
else
net.AddwindowsPrinterConnection (printset)
if err.number <> 0 then
msgbox "You have not typed in a correct printer name" &_
vbcrlf &_
vbcrlf &_
"please try again",64, "Printer setup error"
window.close
end if
end if
Case "location 5"
Case "location 6"
End Select
End Sub
Sub btn02_OnClick
Window.Close
End Sub
</SCRIPT>
<H2>Set Up Printer By Location</H2>
<P>Please select the Site:
<SELECT NAME="site">
<OPTION>location 1</OPTION>
<OPTION>location 2</OPTION>
<OPTION>location 3</OPTION>
<OPTION>location 4</OPTION>
<OPTION>location 5</OPTION>
<OPTION>location 6</OPTION>
</SELECT><P>
<P>Enter Printer Name:
<input type="text" name="BasicTextBox" size="50"><P>
<BR>
<BR>
<Input Type = "Button" Name = "btn01" VALUE = "Set Up Printer">
<Input Type = "Button" Name = "btn02" VALUE = "CLOSE">
<BR>
<BR>
</BODY>
I have a bit of code that I am having a problem w/. I have a little hta that will let a user select their location, then type in the printer name, and then have some vb code run to add the printer connection. I have it set to where if the user just clicks of without typing anything it will error, but if they type in the name of a non-existant printer it just gives a runtime error and i don't know how to make it so it will display the error i want them to see.
thanks in advance
<HEAD>
<TITLE>Set Up Printer By Location</TITLE>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Set Up Printer By Location"
BORDER="Dialog"
CAPTION="Yes"
SCROLL="NO"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="Yes"
WINDOWSTATE="normal">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">
option explicit
on error resume next
dim pc, net, netprint, wmisvc, printobj, printadd, printcol, printer, printset
dim loc, printsrv, print, printname, ements
pc = "."
set net = createobject("wscript.network")
Sub Window_OnLoad
Window.Site.Focus
End Sub
Sub btn01_OnClick
ements = Window.Site.SelectedIndex
loc = Window.Site.Options(ements).Text
print = BasicTextBox.Value
Select Case loc
Case "location 1"
Case "location 2"
Case "location 3"
Case "location 4"
printsrv = "\\location4_server\"
print = BasicTextBox.Value
printset = printsrv & print
msgbox printset
if print = "" then
msgbox "You have not typed in a correct printer name" &_
vbcrlf &_
vbcrlf &_
"please try again",64, "Printer setup error"
window.close
else
net.AddwindowsPrinterConnection (printset)
if err.number <> 0 then
msgbox "You have not typed in a correct printer name" &_
vbcrlf &_
vbcrlf &_
"please try again",64, "Printer setup error"
window.close
end if
end if
Case "location 5"
Case "location 6"
End Select
End Sub
Sub btn02_OnClick
Window.Close
End Sub
</SCRIPT>
<H2>Set Up Printer By Location</H2>
<P>Please select the Site:
<SELECT NAME="site">
<OPTION>location 1</OPTION>
<OPTION>location 2</OPTION>
<OPTION>location 3</OPTION>
<OPTION>location 4</OPTION>
<OPTION>location 5</OPTION>
<OPTION>location 6</OPTION>
</SELECT><P>
<P>Enter Printer Name:
<input type="text" name="BasicTextBox" size="50"><P>
<BR>
<BR>
<Input Type = "Button" Name = "btn01" VALUE = "Set Up Printer">
<Input Type = "Button" Name = "btn02" VALUE = "CLOSE">
<BR>
<BR>
</BODY>