Perplexed by Type mismatch: 'return' Error

Posted on 2009-04-30
Last Modified: 2012-05-06
I made a little HTA application a few months back that simplifies the Active Directory account creation process. I honestly cannot recall ever testing it on any computer besides my own when I made it.  A few days ago, someone else in IT attempted to use the HTA and they had a problem.  It opened fine, but when they hit the drop-down box that lets you select the new user's job title, they received an Internet Explorer script error, which I have attached here.  The application works fine on my computer, but that seems to be the only one.  I have tested on several other machines, but receive the same error wherever I test it.  I'm not sure what to check here to figure out what the heck is causing the issue.  I have also attached all the code below.  I appreciate any assistance.



APPLICATIONNAME="Domain AD Account Creation" 






<title>Domain User Account Creation Form</title> 

<style type="text/css"> 


body,td,th {

        font-family: Arial, Helvetica, sans-serif;

        background-color: #FFFFFF;


.style2 { font-family: Arial, Helvetica, sans-serif; 

font-size: 13.5pt; 

color: #FF0000; 

font-weight: bold; 




        width: 167px;




        width: 220px;





<script type="text/vbscript"> 


'This section is the error reporting for the application 


Sub CreateAccount 

Dim strFinitial

Dim strFirst

Dim strLast

Dim strPassword

Dim strDisplay

Dim strCN

Dim strUser

Dim strTitle

Dim objFolder

Dim objObject


strFinitial = TextBox1.Value 

If strFinitial = "" Then 

MsgBox "You're missing required fields - First Initial",64, "Alert" 

Exit Sub 

End If 


strFirst = TextBox2.Value 

If strFirst = "" Then 

MsgBox "You're missing required fields - First Name",64, "Alert" 

Exit Sub 

End If 


strLast = TextBox3.Value 

If strLast = "" Then 

MsgBox "You're missing required fields - Last Name",64, "Alert" 

Exit Sub 

End If 


strPassword = TextBox4.Value 

If strPassword = "" Then 

MsgBox "You're missing required fields - Password",64, "Alert" 

Exit Sub 

End If

strTitle = JobTitle.Value 

If strTitle = "" Then 

MsgBox "You're missing required fields - Job Title",64, "Alert" 

Exit Sub 

End If  


strDisplay = strFirst & " " & strLast 

strCN = strFirst & " " & strLast 

strUser = strFinitial & "" & strLast





' This section will create the user & set part of the General Page. 

On Error Resume Next

Set objOU = GetObject("LDAP://CN=Users,DC=mydomainname,DC=com") 


If Err Then AdsiErr("Setting objOU")


'On Error GoTo Handler


Set objUser = objOU.Create("User", "cn=" & strCN) 


If Err Then AdsiErr("Setting objUser")


'On Error GoTo Handler


objUser.Put "sAMAccountName", LCase(strUser) 

objUser.Put "userPrincipalName", strUser & "" 

objUser.Put "givenName", strFirst 

objUser.Put "sn", strLast

objUser.Put "company", "My Company"

objUser.Put "countryCode", "840" 

objUser.Put "c", "US"

objUser.Put "displayName", strDisplay

objUser.Put "title", strTitle 



If Err Then AdsiErr("Putting user details in AD")




objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT


If Err Then AdsiErr("Setting user account control")




'objUser.accountdisabled = False



If Err Then AdsiErr("Setting password")


'This Section Will Add the user to the Employees Group 


Set objGroup = GetObject("LDAP://cn=Employees,cn=Users,dc=mydomainname,dc=com") 

objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array("cn=" & strCN & ",CN=Users,dc=mydomainname,dc=com") 



If Err Then AdsiErr("Putting user info in AD")



' This section sets the login script 

objUser.Put "scriptPath", "script.vbs"


If Err Then AdsiErr("Setting login script")


' This section sets the users home drive Information 

objUser.Put "homeDirectory", "\\server1\" & strUser

objUser.Put "homeDrive", "H:" 



intUserFlags = objUser.Get("userAccountControl")

intNewUserFlags = intUserFlags Or UF_DONT_EXPIRE_PASSWD

objUser.Put "userAccountControl", intNewUSerFlags



 If Err Then AdsiErr("Setting home drive info")




'This Section will Create The Users Home Drive on \\server1\Users

Set objFSO = CreateObject("Scripting.FileSystemObject") 

Set objFolder = objFSO.CreateFolder("\\server1\f$\users\users\" & strUser)  

Set FservObj = GetObject("WinNT://MYDOMAIN/NT4/lanmanserver")

Set newshare = FservObj.create("fileshare",strUser)

newshare.path = "f:\users\users\" & strUser



If Err Then AdsiErr("Creating home drive")


'This section sets share and NTFS permissions on the home directory

Set objShell = CreateObject("WScript.Shell") 

objShell.Run "XCACLS \\server1\f$\users\users\" & strUser & " /T /G mydomain\" & strUser & ":C ""mydomain\Domain Admins"":F /y",1 ,True

objShell.Run "SETACL -on \\server1\" & strUser & " -ot shr -actn ace -ace n:mydomain\" & strUser & ";p:change -ace n:""mydomain\Domain Admins"";p:full"

If Err Then AdsiErr("Setting permissions")


' This section creates the Exchange mailbox

Set objOU = GetObject("LDAP://CN=" & strCN & ",CN=Users,DC=mydomainname,DC=com")

objUser.Put "HomeMDB", "CN=Mailbox Store (SERVER2),CN=First Storage Group,CN=InformationStore,CN=SERVER2,CN=Servers,CN=MYDOMAIN,CN=Administrative Groups,CN=MY DOMAIN,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=mydomainname,DC=com"

objUser.Put "mailnickname",strUser

objUser.Put "mDBUseDefaults", TRUE

objUser.Put "mail",strUser & ""


If Err Then AdsiErr("Creating mailbox")


' This section sets the Communication server stuff

Set objUser = GetObject("LDAP://CN=" & strCN & ",CN=Users,DC=mydomainname,DC=com")

strPrimaryUserAddress = "sip:" & objUser.get("mail")

nArchivingEnabled = 0

nOptionFlags = 256

strPrimaryHomeServer = "CN=LC Services,CN=Microsoft,CN=SERVER3,CN=Pools,CN=RTC Service,CN=Microsoft,CN=System,DC=mydomainname,DC=com"

objUser.put "msRTCSIP-PrimaryUserAddress", strPrimaryUserAddress

objUser.put "msRTCSIP-ArchivingEnabled", nArchivingEnabled

objUser.put "msRTCSIP-OptionFlags", nOptionFlags

objUser.put "msRTCSIP-PrimaryHomeServer", strPrimaryHomeServer

objUser.put "msRTCSIP-UserEnabled", True


If Err Then AdsiErr("Setting communication server info")


' The end notification message

MsgBox "User has been created" & vbNewLine & "Employee Name: " & strCN & vbNewLine & "Username: " & strUser & vbNewLine & "Job Title: " & strTitle & vbNewLine & "Home Directory Created and Shared" & vbNewLine & "Exchange Mailbox Created" & vbNewLine & "Communication Server Enabled",64, "Alert" 

End Sub


Sub AdsiErr(strErrorInSection)


        Dim s

        Dim e


        If Err.Number = &H800708B0 Then

                MsgBox "The user " & strUser & " already exists." & vbCRLF & strErrorInSection,64, "Alert"  

        Elseif Err.Number = &H80070035 Then

                MsgBox "Computer not found.  Check the ADsPath and try again" & vbCRLF & strErrorInSection,64, "Alert"

        Elseif Err.Number = "-2147022672" Then

                MsgBox "UserID already exists." & vbCRLF & strErrorInSection,64, "Alert"


        e = Hex(Err.Number)

                MsgBox "Unexpected Error " & e & "(" & Err.Number & ")" & vbCRLF & strErrorInSection,64, "Alert"

        End If



End Sub


Sub Reload 



End Sub 


Sub bodyLoaded() 


window.ResizeTo 510,545 ' WIDTH, HEIGHT 


End Sub 



<script language="javascript" type="text/javascript">

// <!CDATA[

    function Select1_onclick() {


// ]]>



<body onLoad="bodyLoaded()"> 

<p align="center"><img src="tech.jpg" style="height: 142px; width: 136px"></p> 

<p class="style2" align="left"> Tech<font color="#FF0000"> </font>Domain User Account Creation Form<font color="#FF0000">            &nbsp 

<table border="0" align="left" height="59" style="width: 352px"> 


<td width="94" height="14">First Initial:</td> 

<td width="173" height="14"><input type="text" name="textbox1" size="1" 

        maxlength="2" style="width: 20px"></td> 



<td width="94" height="14">First Name:</td> 

<td width="173" height="14"><input type="text" name="textbox2" size="23" 

        style="width: 220px"></td>  



<td width="94" height="14">Last Name: </td> 

<td width="173" height="14"><input type="text" name="textbox3" size="23" 

        style="width: 220px"></td>



<td width="94" height="14">Job Title:</td> 

<td width="173" height="14">

    <select name="jobtitle" onclick="return Select1_onclick()" style="width: 220px">

        <option value=" "> </option>

        <option value="Assistant Project Manager">Assistant Project Manager</option>

        <option value="Assistant Site Manager">Assistant Site Manager</option>

        <option value="Assistant Site Manager Trainee">Assistant Site Manager Trainee</option>

        <option value="Carpenter">Carpenter</option>

        <option value="Contracts Manager">Contracts Manager</option>

        <option value="Estimator">Estimator</option>

        <option value="Executive Assistant">Executive Assistant</option>

        <option value="Field Administrative Assistant">Field Administrative Assistant</option>

        <option value="Field Office Manager">Field Office Manager</option>

        <option value="Project Accountant">Project Accountant</option>

        <option value="Project Engineer">Project Engineer</option>

        <option value="Project Manager">Project Manager</option>

        <option value="Senior Estimator">Senior Estimator</option>

        <option value="Senior Project Manager">Senior Project Manager</option>

        <option value="Site Manager">Site Manager</option>

        <option value="Superintendent">Superintendent</option>




<td width="94" height="14">Password: </td> 

<td width="173" height="14"><input type="text" name="textbox4" size="23" 

        style="width: 220px"></td> 













<input type="button" name="Submit" value="Submit" onClick="CreateAccount"> 



<input id="reloadbutton" class="button" type="reset" value="Clear Form" name="reload_button" onClick="Reload">                                        <font </p> 


<input type="button" value=" Exit " name="close_button" onClick="Self.Close"> 




Open in new window

Question by:HarkinsIT

    Author Comment

    Whoops.  Here's the error message.

    LVL 3

    Accepted Solution

    Hi HarkinsIT,

    Just from taking a quick look through your code - I'm wondering what the call to Select1_onclick() in the select box on line 272 is for - the function is empty and doesn't seem to serve any purpose.  It was probably added automatically by whatever IDE you were using.

    Remove the onclick call and I imagine that this problem will disappear.

    Hope this helps,


    Author Comment

    Dang.  Rookie mistake.  That did the trick.  Thanks very much!
    LVL 3

    Expert Comment

    No problem,

    Glad to be of help.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    The viewer will learn how to count occurrences of each item in an array.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now