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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got it working. I still needed the Exit Do when it found an available name, but it works fine.
Thanks!
Thanks!
Welcome, thanks.
~bp
~bp
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