checking if record exists if it does add 1 and recheck to again ?? help??!!
I tried this in a function but with no luck..
the below code that checks the DB and increaases the number works fine.. but i need to cycle back through it if there is a match and variable i has changed to the next number..
so if i exists then
change number to tx.7_224
now recheck db to see if tx.7_224 exists.... etc...
if tx.7_224 does not exist then = newValue
thanks for anyhelp..
Code:
<%
dim i
dim ID
i = "tx.7_223"
While ((Repeat1__numRows <> 0) AND (NOT rs.EOF))
if UCase(i) = UCase(trim(rs("formNumber"))) then
x=len(i)-3
preID = (left(i,x))
ID = CStr(Right(i,3))
ID = ID + 1
if len(ID) >= 3 then
'continue
elseif len(ID) = 2 then
ID = "0" & ID
elseif len(ID) = 1 then
ID = "00" & ID
end if
i = preID & ID
'response.write UCase(i) & "</br>"
ELSE
'continue
'response.Write("continue") & UCase(rs.Fields.Item("formNumber").Value) & "</br>"
END IF
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rs.MoveNext()
Wend
response.write i
%>
Re: checking if record exists if it does add 1 and recheck to again ?? help??!!
Quote:
Originally Posted by cwfontan
I tried this in a function but with no luck..
the below code that checks the DB and increaases the number works fine.. but i need to cycle back through it if there is a match and variable i has changed to the next number..
Does this mean that the code works for just a single value?
If so, then you should store your "I" variables in an array and loop through the array, iterating through the code once for each element in the array.
You should also consider using a numeric field with auto-increment in the database so that you don't have to reinvent the wheel in your code.
Re: checking if record exists if it does add 1 and recheck to again ?? help??!!
well i figured it out.. all i had to do was add
rs.moveFirst to the iff statement and it works exactly as it should.. see below
thanks
Code:
<%
dim i
dim ID
i = "tx.7_223"
While ((Repeat1__numRows <> 0) AND (NOT rs.EOF))
if UCase(i) = UCase(trim(rs("formNumber"))) then
x=len(i)-3
preID = (left(i,x))
ID = CStr(Right(i,3))
ID = ID + 1
if len(ID) >= 3 then
'continue
elseif len(ID) = 2 then
ID = "0" & ID
elseif len(ID) = 1 then
ID = "00" & ID
end if
i = preID & ID
response.write UCase(i) & "</br>"
rs.movefirst
ELSE
'continue
response.Write("continue") & UCase(rs.Fields.Item("formNumber").Value) & "</br>"
END IF
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rs.MoveNext()
Wend
response.write i
%>