<% Function GetNextOrderCode(strOrderCode) ' gets the next avaiable ordercode after the passed ordercode Dim strNextOrderCode, strSQL, rs, arr, I Dim strLastOrderCode arr = null strSQL = "EXEC stpOrderSimilarSelect " & toSQLStr(strOrderCode) ' returns a list of ordercodes who are sub-codes of this code Set rs = dbconn.Execute(strSQL) If rs.State <> 0 Then If not rs.EOF Then arr = rs.GetRows() rs.Close() End If End If Set rs = Nothing If not isNull(arr) Then GetNextOrderCode = strOrderCode & Chr(Asc(Replace(arr(1,UBound(arr,2)), strOrderCode, "")) + 1) Else GetNextOrderCode = strOrderCode & "A" End If End Function Dim intOrder, strOrderCode intOrder = 10 dump GetNextOrderCode("10") dump GetNextOrderCode("10A") dump GetNextOrderCode("10AA") %>