Link to home
Start Free TrialLog in
Avatar of ajl7519
ajl7519

asked on

VBScript Loop Question

I have the following code that allows users to lookup available user ID's, but I would like to have it go back to original Input Box when an ID is not available to start the search again. I am not quite sure how to setup the loop.

strUserName = "Prefix" & InputBox("Please Enter 4 digit ID without dashes.", "ID Lookup")

dtStart = TimeValue(Now())
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
 
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
 
objCommand.CommandText = _
"<LDAP://OU=TEST,OU=TEST,DC=TEST,DC=NET>;" & _  
"(&(objectCategory=User)" & "(samAccountName=" & strUserName & "));samAccountName;subtree"  

Set objRecordSet = objCommand.Execute
Do 
 If objRecordset.RecordCount = 0 Then
    WScript.Echo "Prefix" & strUserName & " is available."
    Exit Do
 Else 
    WScript.Echo strUserName & " is not available"  
    Exit Do
End If
Loop
objConnection.Close

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

==> - the test for an empty string is never true

I don't understand that comment.  If the user doesn't enter any characters, and just hits enter then that condition certainly will be true, and the loop will exit.

~bp
Avatar of ajl7519

ASKER

I got it working. I still needed the Exit Do when it found an available name, but it works fine.

Thanks!
Welcome, thanks.

~bp