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!

On the fly listbox in HTA

Status
Not open for further replies.

chouck

MIS
Jan 30, 2005
32
US
Hi All,

I have gotten some great help on this site and was hoping to figure this problem out. What I am trying to do is to dynamically populate a list of available printers in a drop down box users can select from. I am connecting to AD in 2003 to get the printer info and want to "import" it dynamically into an hta so a user can select a location, then based on the selection, come up w/ a list of available printers for that locations. Confused yet ? I found this bit of code on another site yesterday and was wondering if anyone had any suggestions for intergrating this into a HTA ???


Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName from " _
& " 'LDAP://ou=bafw, ou=us,DC=behrgroup,DC=net' where objectClass='printQueue'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value
Wscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
objRecordSet.MoveNext
Loop
 
Hi PHV, Yeah I was looking at that one earlier and one on the "Scripting Guy" website as well. This is a very generic version of the code that I am trying to develop. Any suggestions. I have marked the area where I think the problem is occurring I just can't figure it out :(


<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

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
select case location
case "location1"
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName from " _
& " 'LDAP://ou=bafw, ou=us,DC=group,DC=net' where objectClass='printQueue'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
|--------Do Until objRecordSet.EOF
| AvailablePrinters.add objRecordSet.Fields("printerName").Value
|
|--------Loop
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> </OPTION>
<OPTION>location1</OPTION>
<OPTION>location2</OPTION>
<OPTION>location3</OPTION>
<OPTION>location4</OPTION>
<OPTION>location5</OPTION>
<OPTION>location6</OPTION>
</SELECT><P>
<P>
Available Printers: <select> size = "1" name="AvailablePrinters" Name></select><BR>

<BR>
<BR>
<Input Type = "Button" Name = "btn01" VALUE = "Set Up Printer">
<Input Type = "Button" Name = "btn02" VALUE = "Close"><BR>
<BR>

<BR>

</BODY>
 
At least you need the following in your loop:
objRecordSet.MoveNext

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Oh man, I am so close this is what I put in my do/loop:

Do Until objRecordSet.EOF
set objoption= objRecordSet.Fields("printerName").value
AvailablePrinters.add(objoption)
objRecordSet.MoveNext
Loop

now when i run it, it comes up and gives me an error message that says:

Error: Object required: '[string: "ACTUALPRINTERNAME"]'

I am so close I can taste it.
 
what about this ?
Do Until objRecordSet.EOF
Set objOption = Document.createElement("OPTION")
objOption.Text = objRecordSet.Fields("printerName").Value
objOption.Value = objRecordSet.Fields("printerName").Value
AvailablePrinters.Add(objOption)
objRecordSet.MoveNext
Loop

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It worked... I had to juggle a couple of things around, and not exactly sure what I did, but I got it to work. Thank You so much for the help

Curt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top