Results 1 to 3 of 3
  1. #1
    doobybug is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Jan 2009
    Posts
    39

    Checking if values already exist in table

    I have to fields refNo (String) and Volume (Integer) and would like to check if the combination of these 2 fields are already inputted in a table, before I actually save them. If they are already there I don't want to duplicate the record.



    This is giving me a type mismatch. Any ideas why?

    Code:
    If IsNull(DLookup(("[NotaryRefNo]" And [Volume]), "[tblNotaryIndex]", ("[NotaryRefNo]='" & refNo & "'" And "[Volume] = " & Volume & ""))) Then                MsgBox "Record exists"
                End If
                
                sql = "INSERT INTO tblNotaryIndex([NotaryRefNo], [Volume], [Date Start], [Date End], [Condition], [Publication], [Publication Link], [ShelfId]) " & _
                "VALUES('" & refNo & "'," & Volume & ",#" & dateStart & "#,#" & dateEnd & "#, '" & condition & "', '" & publication & "','" & filePath & "','" & shelf & "')"

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    DLookup("anyfieldname on table","tblNotaryIndex","NotaryRefNo='" & refno & "' AND Volume=" & volume)

    Watch the use of parentheses - ( - too many
    Square brackets are optional - only required when field name has spaces or special characters
    Remove the two quotes at the end. Because Volume is a number field the ending quote is not required

    I add a variable to the sub and do: Variable=Dlookup(...). It makes it easier to debug. The result of the DLookup is not always null, sometimes it is blank, sometimes it is zero. I can check it using debug before adding it in to the IF statement.

  3. #3
    doobybug is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Jan 2009
    Posts
    39
    thanks solved!

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

Similar Threads

  1. Replies: 9
    Last Post: 10-31-2015, 10:34 AM
  2. Query to find Values that do NOT exist
    By SoonerLater in forum Queries
    Replies: 4
    Last Post: 09-19-2015, 06:29 PM
  3. Replies: 4
    Last Post: 06-04-2014, 11:55 AM
  4. Checking if data already exist in a Table
    By Phillsoft in forum Forms
    Replies: 2
    Last Post: 08-04-2011, 02:07 PM
  5. Checking if data already exist in a Table
    By Phillsoft in forum Forms
    Replies: 1
    Last Post: 08-04-2011, 08:03 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