Results 1 to 7 of 7
  1. #1
    walter189 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    7

    Checking if a year exists via DLookup

    Scenario:


    In the table [Entry Data] I have fields [Symbol Number] and [Date Tested] that i'm using as the basis for my DLookup. I need to see if the symbol number a user entered in a form along with a date (more specifically it's year) exist among the records. I am basically trying to debug it right now by entering data into the form that I know a record exist for but it still is telling me that i'm getting a null value.
    Here's my code (any thoughts into what i'm doing wrong would be greatly appreciated:

    If IsNull(DLookup("[Symbol Number]", "[Entry Data]", "[Symbol Number] = '" & Symbol_Num2 & "' AND Year([Date Tested]) = Year(" & Begin_Date & ")")) = True Then . . .

    Records exist for the symbol number and year from the date field associated with the symbol number which i enter in my form

  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,521
    I don't see anything right off. What's the data type of [Symbol Number]? Add this line:

    Debug.Print "[Symbol Number] = '" & Symbol_Num2 & "' AND Year([Date Tested]) = Year(" & Begin_Date & ")"

    And check the result in the VBA Immediate window. If you don't spot the problem, post the result here.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If IsNull(DLookup("[Symbol Number]", "[Entry Data]", "[Symbol Number] = '" & Symbol_Num2 & "' AND Year([Date Tested]) = Year(" & Begin_Date & ")")) = True Then . . .
    Why are you looking up a value for a value you already have?

    You're looking up [symbol number] when you already have the symbol number you're looking it up with.

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

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if it were purely a test for existence it would be a dcount function, he's trying to recover a value from a dataset not find out if there are any records.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Perhaps I misunderstood this:

    I need to see if the symbol number a user entered in a form along with a date (more specifically it's year) exist among the records

    I personally would use DCount, but this DLookup test will still work.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I think we need more input from the original poster

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

Similar Threads

  1. Automatically checking a box?
    By Delta223 in forum Access
    Replies: 3
    Last Post: 01-10-2011, 10:37 PM
  2. Checking a table for changes
    By Rando in forum Queries
    Replies: 2
    Last Post: 10-07-2010, 09:25 AM
  3. Date error checking
    By oediaz in forum Programming
    Replies: 2
    Last Post: 03-26-2010, 12:08 PM
  4. Checking if files exists
    By geoffishere in forum Access
    Replies: 1
    Last Post: 02-09-2010, 01:32 PM
  5. Checking for Value in Query
    By jgelpi in forum Access
    Replies: 1
    Last Post: 06-24-2009, 04:57 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