-
Jul 19th, 2015, 04:01 PM
#1
Thread Starter
Hyperactive Member
no duplicates/clones
this is the routine im using to check if the name Exists on the database
the problem im having
if the name to check is identical ..its lets you register
so if Rattled_Cage is in the database already it knows it exists and refuses registration
but register as
Rattled_cage or rattled_cage it registers as a new user
how do i stop that . . . .
Code:
'''''''''''''check if username exists
Dim User_To_Check As String
User_To_Check = Split(Data, "¦")(1)
Dim db As dao.Database
Set db = currentDb
Set rs = db.OpenRecordset("Master") 'myTable is a MS-Access table created previously
'populate the table
rs.MoveLast
rs.MoveFirst
User_Exists_Already = False
Do While Not rs.EOF
If (rs!User_Name) = User_To_Check Then '''"Found username CHOOSE ANOTHER"
User_Exists_Already = True
End If
If User_Exists_Already = True Then
Server.SendData "Found username CHOOSE ANOTHER", SckIndex
Exit Sub
End If
rs.MoveNext 'press Ctrl+G to see debuG window beneath
Loop
'''''''''end if checking if hes there
-
Jul 19th, 2015, 04:07 PM
#2
Thread Starter
Hyperactive Member
Re: no duplicates/clones
ah ok i think ive solved it with this
Code:
If StrComp((rs!User_Name), User_To_Check, vbTextCompare) = 0 Then
User_Exists_Already = True
end if
-
Jul 19th, 2015, 04:24 PM
#3
Lively Member
Re: no duplicates/clones
Code:
.........
dim t1 , t2 As String
t1=UCase$(User_To_Check)
Do While Not rs.EOF
t2=UCase$(rs!User_Name)
If t1=t2 Then '''"Found username CHOOSE ANOTHER"
User_Exists_Already = True
End If
......
Loop
-
Jul 19th, 2015, 05:09 PM
#4
Thread Starter
Hyperactive Member
Re: no duplicates/clones
Originally Posted by JackB
Code:
.........
dim t1 , t2 As String
t1=UCase$(User_To_Check)
Do While Not rs.EOF
t2=UCase$(rs!User_Name)
If t1=t2 Then '''"Found username CHOOSE ANOTHER"
User_Exists_Already = True
End If
Loop
thanks that may be a better way
-
Jul 20th, 2015, 01:09 AM
#5
Re: no duplicates/clones
You really should be using ADO rather than the old outdated DAO stuff.
You also should not be looping through the recordset to find the name, instead you should use a select query and a where clause this is true no matter if you are using DAO or ADO
Using modified version of your code from above
Code:
Set rs = db.OpenRecordset("Select * from Master where [User_Name]='" & User_To_Check &"'") 'myTable is a MS-Access table created previously
User_Exists_Already=Not RS.EOF
Replaces
Code:
Set rs = db.OpenRecordset("Master") 'myTable is a MS-Access table created previously
'populate the table
rs.MoveLast
rs.MoveFirst
User_Exists_Already = False
Do While Not rs.EOF
If (rs!User_Name) = User_To_Check Then '''"Found username CHOOSE ANOTHER"
User_Exists_Already = True
End If
If User_Exists_Already = True Then
Server.SendData "Found username CHOOSE ANOTHER", SckIndex
Exit Sub
End If
rs.MoveNext 'press Ctrl+G to see debuG window beneath
Loop
Note: Select * is frowned upon and really should not be used. I added it here because I do not know what you are doing with that recordset if anything after the check such as adding a new record or whatever. If you are just testing then that * should be removed and replaced by a field name i.e
Code:
Set rs = db.OpenRecordset("Select [User_Name] from Master where [User_Name]='" & User_To_Check &"'")
Last edited by DataMiser; Jul 20th, 2015 at 01:13 AM.
-
Jul 20th, 2015, 04:37 AM
#6
Thread Starter
Hyperactive Member
Re: no duplicates/clones
thats compacted the code alot : ) cheers
how do i swap over to ado is it just more reliable ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|