Results 1 to 4 of 4
  1. #1
    CoMik is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    2

    Comoare/Check if Records are duplicate using save button


    Hi,

    I am new to Access or Vb but then I need to create a record of Users. I created a form with fields containing Username,FirstName,LastName & Email Address wherein the UserName is equals the value of the fields FirstName & LastName. I have a save command button and when I click it, I want it to be able to check if the new entry has a similar UserName that exists in the database, if it exists then it will allow me to edit the UserName and then save the data otherwise will allow me to save it. Can you please help me? I am just a novice in programming. Many thanks in advance.
    Last edited by CoMik; 01-09-2014 at 05:28 PM. Reason: wrong spelling

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe the Dcount function. This link's title says Method. I guess when you consider Application...
    http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

    If you get a return >=1 then there is a match. Another option is DAO and the .Findfirst method.

  3. #3
    CoMik is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    2
    Hi, Can you please help..I can't get it to work...currently this is my code..the save button is not working...Thanks

    Private Sub cmdSave_Click()
    If DCount("*", "tblUsers", "UserName=" & Chr(34) & Me.UserName & Chr(34)) > 0 Then
    MsgBox "This username already exists!", vbExclamation
    Cancel = True
    Else
    DoCmd.RunCommand acCmdSaveRecord

    End If

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe
    If DCount("UserName", "tblUsers", "UserName=" & Me.UserName & )> 0 Then
    Here the field UserName is being counted. I usually count the primary key field. I guess a wildcard like in the example I linked to would work too. Never tried it.
    Also, your canceling a click event. Not sure what you are trying to cancel here. I see you have the save command but... Usually user input is validated using the before update event handler.

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

Similar Threads

  1. Replies: 6
    Last Post: 07-11-2012, 10:13 PM
  2. check duplicate records within same table
    By cthorn112 in forum Queries
    Replies: 0
    Last Post: 06-19-2012, 12:23 PM
  3. Replies: 7
    Last Post: 10-28-2011, 03:42 AM
  4. Replies: 2
    Last Post: 06-09-2011, 09:47 AM
  5. Replies: 10
    Last Post: 04-19-2011, 03:38 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