Richard
Sun Jul 29 12:55:42 CDT 2007
Yas wrote:
> I have a script that goes through a RecordSet containing user details
> and creates them in Active Directory.
>
> So I have Main Loop something like
>
> Do Until adoRecordset.EOF
>
> <user creation statements, clauses, conditions>
>
> adoRecordSet.MoveNext
> Loop
>
> Within this Main Loop there are lots of conditions/clauses IF Else...
> Do While...Do Until etc
>
> Is there a way if certain condition is not met or an error occurs I
> can just skip that user and move down to the end to
> adoRecordSet.MoveNext? I know I can use Exit Do, Exit IF etc but if I
> say that I dont want the script to process any of the following
> statements loops etc for that failed user and Exit to the main Do
> Until adoRecordset.EOF Loop and move to the next RecordSet (user).
>
> so exit to the last statement in the Main Loop (adoRecordSet.MoveNext)
>
One solution is to nest the If Then statements, but that doesn't handle Do
Until loops well. Another solution is to call a subroutine in the recordset
loop. If any condition is wrong, simply exit the sub. Place all processing
for each user in the Sub. You would need to retrieve values from the
recordset before calling the sub. You can pass these values as parameters.
For example:
==============
Do Until adoRecordset.EOF
strVar1 = adoRecordset.Fields("Var1").Value
strVar2 = adoRecordset.Fields("Var2").Value
strVar3 = adoRecordset.Fields("Var3").Value
strVar4 = adoRecordset.Fields("Var4").Value
Call CreateUser(strVar1, strVar2, strVar3, strVar4)
adoRecordset.MoveNext
Loop
adoRecordset.Close
Sub CreateUser(strVar1, strVar2, strVar3, strVar4)
' Process values from recordset.
If (strVar1 = "") Then
' Necessary condition not met.
Exit Sub
End If
' More processing.
End Sub
===========
Or you could use a Function and return a non-zero value if an error is
encountered, a zero if no errors.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net
--