Results 1 to 4 of 4
  1. #1
    Fox359 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jan 2020
    Posts
    2

    Message Box for Duplicates

    I'm a novice and am having trouble getting a message box to work. I would like a message box to appear when someone is entering or updating a number in a control in a subform when there is a duplicate. The message box can then allow the person to continue (keep the duplicate if it's intentional) or delete the entire record (if it wasn't intentional).

    I have the following coding for AfterInsert and AfterUpdate for the control in the subform:

    If DCount("*", " Database-Number ", "[Number]="& Chr(34) & [Number] & Chr(34)) > 1 Then
    Call MsgBoxDuplicate
    End If

    I have entered the following for the message box in the subform, but nothing happens:

    Sub MsgBoxDuplicate()

    Dim answer As Integer
    answer = MsgBox("This number has already been entered. Would you like to continue? If this is an intentional duplicate, press Yes continue entering information. Otherwise press No to delete this entry.", vbYesNo + vbExclamation, "Duplicate Entry")

    If answer = vbNo Then

    answer = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbCritical, "Delete")

    If answer = vbYes Then

    DoCmd.RunCommandacCmdDeleteRecord

    End If

    End If



    I tried starting with the basic coding and then adding one section at a time to figure out where the problem is. The message box appears for duplicates if I do this:


    Sub MsgBoxDuplicate()





    MsgBox"This number has already been entered. Would you like to continue? If this is an intentional duplicate, press Yes continue entering information. Otherwise press No to delete this entry.", vbYesNo + vbExclamation, "Duplicate Entry"

    but as soon as I add "answer=(…)" it no longer appears. Any help would be much appreciated.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    First, get rid of the spaces:
    If DCount("*",
    " Database-Number ", "[Number]="& Chr(34) & [Number] & Chr(34)) > 1 Then

    It that doesn't work, get rid of the delimiters around Number (If Number is a number)

    If DCount("*", "Database-Number", "[Number]=" & Number) > 1 Then

  3. #3
    Fox359 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jan 2020
    Posts
    2
    Sorry, I realize how misleading that is. While it's referred to as a "number", the original data that was imported had a dash in the middle so the field is short text.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Quote Originally Posted by Fox359 View Post
    Sorry, I realize how misleading that is. While it's referred to as a "number", the original data that was imported had a dash in the middle so the field is short text.
    EDIT:

    The first argument is the name of the field you are looking for ("*") which is anything
    The second argument is the domain (the table or query) containing the first argument (is that Database-Number or Number?).


    Code:
    If DCount("*", "Database-Number", "Number=" & Chr(34) & [Number] & Chr(34)) > 1 Then
    Which means "Count any record in Database-Number where Number = this number"

    Notice removal of spaces in red Database-Number and removal of brackets in Number.
    Last edited by davegri; 01-22-2020 at 12:47 PM. Reason: Added Edit:

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

Similar Threads

  1. Replies: 3
    Last Post: 05-13-2018, 12:59 AM
  2. Replies: 5
    Last Post: 12-24-2017, 02:38 PM
  3. Replies: 3
    Last Post: 01-18-2016, 01:55 PM
  4. Pop up Message on Duplicates Error.
    By Torinjr in forum Forms
    Replies: 11
    Last Post: 06-09-2015, 07:30 PM
  5. Replies: 9
    Last Post: 09-26-2012, 12:20 PM

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