Results 1 to 4 of 4
  1. #1
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63

    Comparing Data Entered in a Field to a Query to Determine if it's a Duplicate Entry

    Hello,



    I have a field on a form that will be filled out by a user. I need to have the ability to run the data that is input in the field against a query to see if there is a match. If there is a match, I need it to show an error message and require the user to enter new data.

    For example, field name is Phone Number.
    I have a query for all of the phone numbers that were entered in the original table.
    After updating the phone number field, I need to have the input phone number look against the phone number query to see if it exists.
    If it exists, then an error message needs to come up requiring a different input.
    If it does not exist, nothing happens.

    Right now, I have an 'After Update' macro on the phone number field in the form. I have an If statement that reads:

    If [Forms]![Customer Form]![Phone Number] = [Phone Number Lookup]![Phone Number] Then
    MessageBox
    Message: You have entered a duplicate phone number!
    Beep: Yes
    Type: Warning!
    Title: Duplicate Phone Number
    End If

    When I try to execute this, the error message that I receive is the following:

    Microsoft Access cannot find the name 'Phone Number Lookup' you entered in the expression.

    You may have specified a control that wasn't on the current object without specifying the correct form or report context.

    To refer to a control on another form or report, precede the control name with the name of a collection. This is usually either Forms or Reports, and the name of the form or report to which the control belongs. For example, Forms![Products]![Units In Stock].


    Is it because that I can't run an if statement against a query? If not, is there another way I can accomplish this. (FYI: I cannot just adjust the index property in the database to say no duplicates, I need to know if it's a duplicate as soon as data is entered in the field before the rest of the form is filled out)

    Thank you in advance.

    Cory

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You can't get the value that way. Use DCount() with a criteria and test for >0.

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    How would I do that?

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    If DCount(...) > 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 03-09-2014, 07:16 PM
  2. Replies: 14
    Last Post: 01-07-2014, 04:20 PM
  3. Replies: 2
    Last Post: 07-30-2012, 03:26 PM
  4. Replies: 1
    Last Post: 06-09-2011, 07:11 PM
  5. Replies: 4
    Last Post: 05-28-2011, 01:20 AM

Tags for this Thread

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