Results 1 to 5 of 5
  1. #1
    New.User is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    37

    Prevent Duplicates From one listbox to another

    I have two listboxes viz. listComponents and listAdditions with a button to add or double click on the items. What I am looking for is a code where in the listAdditions should not populate duplicate items. If an item already exists and user presses the button he must get a pop up mesg saying "item already exists".
    Any help with the coding will be appreciated.



    Regards
    New.User

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Use an If clause with a DLookup similar to this

    Code:
    If Nz(DLookup(fieldname, tablename, criteria),"")<>"" Then
        MsgBox "This item already exists"
    End If
    Your criteria would be whatever selection has just been made

    HTH
    Last edited by isladogs; 04-12-2018 at 02:57 AM. Reason: Added text
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    New.User is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    37
    I am a bit allergetic to Dlook up as I always make mistake and at the end of the day i start to debug the error. Is there a simpler way?

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I suggested that as the simplest method.
    An alternative would be to use a count query and look for a count >0 but its different rather than easier.

    Usually any issues with DLookups are to do with getting any delimiters correct
    Its worth trying to learn how to do things like this as it will make your database much more powerful

    Why not try it and post your efforts if you have issues
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    New.User is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    37
    Yeah, you are right. I will give it a try and post if i come up with any issues. Thank you RIdders.

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

Similar Threads

  1. Prevent Duplicates
    By Koolaid in forum Access
    Replies: 4
    Last Post: 03-31-2016, 09:37 AM
  2. Prevent Duplicates Upon Selection from Combo Box
    By xx_phenom_xx in forum Programming
    Replies: 5
    Last Post: 04-28-2015, 09:30 AM
  3. Prevent Group By eliminating duplicates
    By bruegel in forum Queries
    Replies: 3
    Last Post: 03-27-2014, 07:55 AM
  4. Dlookup to prevent duplicates
    By arothacker in forum Access
    Replies: 16
    Last Post: 02-12-2014, 11:40 AM
  5. How to prevent duplicates in said example
    By raymondbeckham in forum Forms
    Replies: 1
    Last Post: 04-11-2012, 03:29 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