Results 1 to 6 of 6
  1. #1
    Feddy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2016
    Location
    Space Coast Florida
    Posts
    11

    on save/close need to create error on duplicate information

    i would like for my form to display an error upon seeing duplicate information in a particular field.

    i already created a query based on a table that includes all of the records fields that i want to base this error on, i created a macro that says: if [Service Tag#] = [ServiceTagQry]![Service Tag#] then 'MessageBox' error name blahblah (see picture below) stopmacro
    end if
    close window
    save

    but it errors saying:Click image for larger version. 

Name:	err1.JPG 
Views:	11 
Size:	46.7 KB 
ID:	26718




    full macro:Click image for larger version. 

Name:	Macro1.JPG 
Views:	11 
Size:	34.0 KB 
ID:	26719


    i would totally be open to a vba solution, i just don't know how to code it.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    use the Query Wizard, create a FIND DUPLIATES QUERY.
    run this query after input. This is the error list.

  3. #3
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Also, please don't use "#" in your field names. It can cause wonkiness.

  4. #4
    Feddy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2016
    Location
    Space Coast Florida
    Posts
    11
    Right, but i dont want a query to come up every time i insert a field, i want it to give a dumb error if i have already used that tag in the past.

    also yes i know i messed up by using the '#' but with all of the references that already exist in my database, i would rather not rename it.

  5. #5
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Quote Originally Posted by Feddy View Post
    Right, but i dont want a query to come up every time i insert a field, i want it to give a dumb error if i have already used that tag in the past.

    also yes i know i messed up by using the '#' but with all of the references that already exist in my database, i would rather not rename it.
    You could try this. I use it to prevent duplicate customer names (replace my references with yours)
    Code:
    'Check to see if record exists
    Dim FNAME As String
    Dim LNAME As String
    Dim namecriteria As String
    Dim rsc As DAO.Recordset
     
    Set rsc = Me.recordsetclone
     
    FNAME = Me.[First Name].Value
    LNAME = Me.[Last Name].Value
     
    Namecriteria = "[First Name]=""" & FNAME & _
    """ AND [Last Name]=""" & LNAME & """"
     
    'Check Customer Data Table table for duplicate
    If dcount("*", "customer data", namecriteria) > 0 Then
     
    'Message box warning of duplication
    Select Case msgbox("Customer name already exists!" & vbnewline & _
    "Click 'Yes' to view the existing customer record," & vbnewline & _
    "Click 'No' to add a duplicate customer record," & vbnewline & _
    "Click 'Cancel' to discard all changes.", vbyesnocancel + vbexclamation)
     
    Case vbyes
    'Go to record of original record'
    Docmd.openform "customerdata", acnormal, , namecriteria
     
    'Me.Undo
    Rsc.findfirst namecriteria
    'Me.Bookmark = rsc.Bookmark
     
    Case vbno
    'Allow save
    Cancel = False
    Forms!Customerdata.firstname.setfocus
     
    Case vbcancel
    'Stop the save and undo the form
    Me.Undo
    Msgbox "Add a New Customer or Select the Existing Customer From the 'Lookup Customer’ Function."
    Forms!Frmcustomers.firstname.setfocus
     
    End Select
    End If
     
    Set rsc = Nothing
     
    End Sub

  6. #6
    Feddy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2016
    Location
    Space Coast Florida
    Posts
    11
    thank you Gina, i will work on this tomorrow!

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

Similar Threads

  1. Replies: 4
    Last Post: 09-16-2013, 05:55 AM
  2. Every time I close or save changes
    By Opid in forum Access
    Replies: 1
    Last Post: 06-18-2012, 07:43 AM
  3. Save and close
    By brobb56 in forum Forms
    Replies: 4
    Last Post: 10-10-2011, 03:07 PM
  4. Can't save or close form
    By Buakaw in forum Forms
    Replies: 4
    Last Post: 07-26-2011, 04:47 AM
  5. Access Form- Save/Close Button error
    By Ashe in forum Forms
    Replies: 3
    Last Post: 02-10-2011, 01:01 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