This topic is locked

Prevent identical user name

10/14/2009 11:18:47 AM
ASPRunnerPro General questions
T
text author

Hi
I have a project that when members are about to create a username I would like to be able to check whether their chosen user name exists in the database. I can see that this needs to be a before add event and am guessing that it's possible to modify the "check if record exists" code supplied but I am not sure exactly what that modification would be. I know what my table and column are but how does the AnyValue correspond to the username that is being chosen and how would I modify the code to say "This username is already taken."
I should add that I am using a Mysql database.
Please can someone help, the code that asprunner provides is below
dim rsExists

set rsExists = dal.AnyTable.Query("AnyColumn='AnyValue'","")

if not rsExists.eof then

' if record exists do something
else

' if dont exist do something else
end if

rsExists.Close : set rsExists = Nothing
Thanks
Richard

Sergey Kornilov admin 10/14/2009

To access value of any field on the form use values("FieldName")
Try the following (replace field names in bold with the actual ones).

dim rsExists

set rsExists = dal.AnyTable.Query("AnyColumn='" & values("UserNameField") & "'","")

if not rsExists.eof then

' if record exists do something
else

' if dont exist do something else
end if

rsExists.Close : set rsExists = Nothing

T
text author 10/15/2009



To access value of any field on the form use values("FieldName")
Try the following (replace field names in bold with the actual ones).


Hi Sergey that's great thank you very much. How do I extend that to include a where statement so that I can filter the search by another field in the table as well ? So essentially what I am trying to do is check that a user can't use a duplicate name in their own data however a different user could have the same field name.
Thanks
Richard

Sergey Kornilov admin 10/15/2009

Just add one more condition to your existing WHERE clause:

set rsExists = dal.AnyTable.Query("AnyColumn='" & values("UserNameField") & "' and SomeOtherField=SomeOtherValue","")

T
text author 10/16/2009



Just add one more condition to your existing WHERE clause:


Thanks Sergey I know I am doing something stupid with the single and double quotes but for the life of me I can't see what, I've tried copying your code above and many variations of single and double quotes but just cannot get it to work. Can you see any obvious errors below.
set rsExists = dal.member_details.Query("Site_Alias='" & values("Site_Alias") & "' and "idMembers='" & values("idMembers"),"")
Thank you very much

J
Jane 10/16/2009

Hi,
please check my changes below:

set rsExists = dal.member_details.Query("Site_Alias='" & values("Site_Alias") & "' and idMembers='" & values("idMembers") & "'","")
T
text author 10/16/2009



Hi,
please check my changes below:

set rsExists = dal.member_details.Query("Site_Alias='" & values("Site_Alias") & "' and idMembers='" & values("idMembers") & "'","")



Jane
Thank you so much I tried just about every variation apart from that. I cannot thank you and Sergey enough for all of the help that you give. Fantastic product and great support.
Thanks again.
Richard