Results 1 to 3 of 3
  1. #1
    Lucas83 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    6

    Check if value exist in a table

    Hi everyone, I hope anyone can help me:

    I have a textbox and a save button. When I write something into the textbox and I click the save button, what I wrote into the textbox is saved in a table. However, If I click the button again the data is saved again, and therefore, duplicated. What I want is to check if the data entered in the textbox is already in the table or not. The table has three columns, a ID column, a column with text, and a column with numbers (this last column is used to connect with other table). I tried using DLookup:

    variable = DLookup("Idcity","City", "Idcity = '" & Text5 & "'")

    Text5 is a textbox that shows a number from other table. I used that number to identify the idcity from the table City. I used an if to check if the number exists in City table:



    If variable = 0 Then

    CurrentDb.Execute (Insert into...)

    Else

    CurrentDb.Close

    However I get an error in DLookup saying that data types in criteria don't match. I've been looking for a code doing something similar but I wasn't successful, so I hope someone can help me. Thank you in advance! you're great!!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Lucas83 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    6
    Thank you for your reply!!, I used Dcount as other user from access-programmers suggested and It worked. ^^

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

Similar Threads

  1. Form doesn't exist
    By Back2Basics in forum Access
    Replies: 1
    Last Post: 02-01-2010, 11:39 AM
  2. Query: How many times does a value exist?
    By hognabbt in forum Queries
    Replies: 1
    Last Post: 01-10-2010, 01:33 PM
  3. Replies: 0
    Last Post: 10-19-2009, 11:11 AM
  4. Replies: 0
    Last Post: 04-19-2008, 09:08 PM
  5. Replies: 1
    Last Post: 08-22-2006, 04:27 AM

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