You are comparing the username "fred" with the UserID (5)
I'm no SQL expert, but there should be a SQL string to do this rather than walking through the recordset.
how about something like;
sql "SELECT UserID FROM tblusers WHERE username= '" & username & "';"
if this returns an empty recordset then you know that the user is unique, if not then you have the ID of the row and you can use this to update or report.
I always stick a line like
response.write (sql & "<br>") underneath the above so that I can see what my SQL statement ended up being. Then comment it out when its all working.
Also, if you response.redirect in the middle of the script you will leave the recordset object open, tying up server resources?
Mark