Results 1 to 6 of 6

Thread: no duplicates/clones

  1. #1

    Thread Starter
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    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

  2. #2

    Thread Starter
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    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

  3. #3
    Lively Member
    Join Date
    Apr 2015
    Posts
    120

    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

  4. #4

    Thread Starter
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: no duplicates/clones

    Quote Originally Posted by JackB View Post
    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

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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.

  6. #6

    Thread Starter
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    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
  •  



Click Here to Expand Forum to Full Width