Results 1 to 4 of 4
  1. #1
    anwaar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    18

    Error on entering duplicate value

    Guys,

    I am designing a "User Registration" form in which I have 5 textboxes and 1 command button:

    Text Boxes:
    ---------------
    UserFullName
    Username
    Password
    Password2
    UserType


    Command Button:
    -------------------


    cmdRegister


    Now the problem is, I want if any duplicate 'username' is going to be registered then VBA should display an error message like "Username already exists."

    Kindly help me out.

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Why not just set the property in the table for the username field to No duplicates.

    Alan

  3. #3
    anwaar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    18
    Dear alansidman,

    Really thanks for your instent reply, I know this way to do it but the problem is I want to do it through VBA, because by using Index property (No Duplicates), it returns a VBA error (Debug) due to this code line "DoCmd.GoToRecord , , acNewRec". That's why I want to do it complete through VBA.

    So Please review it and Help me
    (QdEvaluators is Query which retrieve only 'Usernames' from original table)

    Code:
    Private Sub cmdRegister_Click()
    If DLookup("[Username]", "QdEvaluators") = Username Then
        MsgBox "Username already exists.", vbCritical, "Username"
        userFullName.Value = ""
        Username.Value = ""
        Password.Value = ""
        Password2.Value = ""
        UserType.Value = "User"
    Else
        If Not Password.Value = Password2.Value Or Password.Value = "" Or Password2.Value = "" Then
            MsgBox "Password and Verify Password should be matched, and should not blank.", vbCritical, "Password"
            userFullName.Value = ""
            Username.Value = ""
            Password.Value = ""
            Password2.Value = ""
            UserType.Value = "User"
        Else
            If userFullName.Value = "" Or Username.Value = "" Then
                MsgBox "Name/Username fields should not blank.", vbInformation
            Else
                MsgBox "Congratulations, New user is successfully registered.", vbInformation
                DoCmd.GoToRecord , , acNewRec
                DoCmd.Close
            End If
        End If
    End If
    End Sub

  4. #4
    anwaar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    18
    Thanks Guys

    I have done it using Recordset and SQL Count function.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Duplicate Entry Error
    By Dee300 in forum Forms
    Replies: 3
    Last Post: 08-16-2011, 07:29 PM
  2. Replies: 1
    Last Post: 06-15-2011, 03:29 PM
  3. Replies: 2
    Last Post: 03-29-2011, 01:26 PM
  4. Replies: 0
    Last Post: 03-15-2010, 02:38 AM
  5. Entering duplicate data in Form
    By cotri in forum Forms
    Replies: 1
    Last Post: 01-06-2010, 11:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums