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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a tree-view of Organisational Units in HTA

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
Hi,

I read a post that is unfortunatly closed. In it PScottC gives me the perfect code I need to populate a list box of OU's with indents. thread931-1474595

Problem I have, is that I need to but the main section into a Function or Sub so I can call it from the onLoad event of an HTA. I originally had the code in a <script> tag in the HTA, so to get arround my issue I put the code into a linked vbs file. The section of my code that builds the Select object can't find object "document".

All I can think of is because the vbs file is linked rather than in the HTA, it is causing it problems finding the select object.

I'd be grateful if anyone could point me in the right direction for putting the code in a function or sub, or fixing the document object problem.

The code where the "object required: document" error occures is shown below. Line 8

Code:
Sub RecurseOUs(ByRef oADOConnection, ByRef oADOCommand, ByVal sSearchRoot, sTab)
    Dim oRecordSet, i, objOption, myForm1, TA_OU, document, out

    oADOCommand.CommandText = sSearchRoot & ";" & sFilter & ";" & sAttribs & ";" & sScope
    Set oRecordSet = oADOCommand.Execute
	i= 0
    Do Until oRecordSet.EOF
        Set objOption = document.createElement("OPTION")
		objOption.text = sTab & oRecordSet.Fields("name").Value
		objOption.Value = i+1
		myForm1.TA_OU.Add(objOption)
        'out= sTab & oRecordSet.Fields("name").Value
       ' MsgBox out
        ' or perform "stuff" to insert information into HTA
		
        sSearchRoot = "<LDAP://" & oRecordSet.Fields("distinguishedName").Value & ">"

        Call RecurseOUs(oADOConnection, oADOCommand, sSearchRoot, sTab & vbTab)

        ' Move to the next record in the recordset.
        oRecordSet.MoveNext
    Loop

    ' Close RecordSet
    oRecordSet.Close
End Sub

Many thanks and many thanks to PScottC for saving many hours of scripting :) (probably not a good thing!)

Woter
 
I assume that RecurseOUs is called from the HTA and thus I suggest to add a parameter for the document object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PH,

Been thinking about this since you posted your reply, yet I'm still not sure what you mean by adding a parameter.

Any chance of an example?

Many thanks

Woter
 
Thinking alot more about this, RecurseOUs is called from the modal HTA, not from the main hta.

The code in the modal HTA (outside of the RecurseOUs function):

Code:
Option Explicit


Dim oDSE, oADOConnection, oADOCommand, sSearchRoot, sDNC, loadPage

' Bind to AD... Future 'gets' will not re-bind (efficient)
Set oDSE = GetObject("LDAP://rootDSE")

' Setup ADO Connection to Active Directory
Set oADOConnection = CreateObject("ADODB.Connection")
With oADOConnection
    .Provider = "ADsDSOObject"
    .Open "Active Directory Provider"
End With

' Setup ADO Command parameters
Set oADOCommand = CreateObject("ADODB.Command")
With oADOCommand
    .ActiveConnection = oADOConnection
    .Properties("Page Size") = 1000
    .Properties("Timeout") = 30
    .Properties("Cache Results") = False
End With

sDNC = oDSE.Get("defaultNamingContext")

sSearchRoot = "<LDAP://ou=All Family Mosaic Test," & sDNC & ">"
Const sFilter = "(&(objectClass=organizationalUnit))"
Const sAttribs = "distinguishedName,name"
Const sScope = "onelevel" ' "subtree"

call RecurseOUs(oADOConnection, oADOCommand, sSearchRoot, "")

It's basically the same as written by PScottC. The reason I am lost on this is because I would assume the modal HTA should run on its own, but I still get the error "object required: 'document'". It's only modal if its called from the main HTA.

Many thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top