Results 1 to 4 of 4
  1. #1
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317

    Getting form to recognize duplicate dates

    Folks

    For some reason, the following code works ...
    Code:
    If DLookup("ReviewDate", "ReviewDateTable", "DocumentID = " & Me.Parent!DocumentID.Value) = Me!ReviewDate.Value Then _
    MsgBox "This review date has already been entered for this document.", vbInformation
    ... but this doesn't ...


    Code:
     
    If DCount("ReviewDate", "ReviewDateTable", "DocumentID = " & Me.Parent!DocumentID.Value & "And ReviewDate = " & Me!ReviewDate.Value) > 0 Then _
    MsgBox "This review date has already been entered for this document.", vbInformation
    To be more specific, in the first instance it's recognized that the review date is already in the table, but in the second instance it isn't recognized. Can anyone help me as to why? (For info, I need something akin to the second, as each document can have several review dates.)

    Thanks

    Remster

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    well here is a suggestion - though it is a bit of a cop out - rather than string together an AND statement involving form & subform - - instead wrap it with if/then logic.....

    take out: & "And ReviewDate = " & Me!ReviewDate.Value) > 0

    to get back to the IF dcount string that you know works...

    and then wrap that string with another if/then:

    If Me!ReviewDate.Value) > 0 then

    **put your simpler IF dcount statement here

    end if

    kinda lame but probably works.....

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    "Value" is the default property, so you don't need to add it. And I'm not a big fan of the single line IF statement syntax.

    I did notice a couple of things..... Brackets are not required around field names but it helps. You should have delimiters around the date control.
    And you are missing a space in front of the "AND".

    Try this:

    Code:
       If DCount("[ReviewDate]", "ReviewDateTable", "[DocumentID] = " & Me.Parent!DocumentID & " And [ReviewDate] = #" & Me!ReviewDate & "#") > 0 Then _
          MsgBox "This review date has already been entered for this document.", vbInformation

  4. #4
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Thanks, I worked that out independently last night! I already had the space before the 'And' (what I posted was simplified version of my code, but I made a typo). The key was the delimiters, by which I assume you mean '#'. I had a feeling I needed something like that but couldn't quite work out how to formulate it.

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

Similar Threads

  1. Duplicate form
    By Lea in forum Forms
    Replies: 11
    Last Post: 08-24-2013, 09:37 AM
  2. List Box Not Recognize OnKeyPress ENTER
    By Rawb in forum Programming
    Replies: 1
    Last Post: 02-14-2011, 08:04 AM
  3. Mixed dates - show only complete dates?
    By weeblesue in forum Queries
    Replies: 3
    Last Post: 10-27-2010, 02:15 PM
  4. Replies: 1
    Last Post: 07-21-2009, 03:01 PM
  5. Access does not recognize field
    By Shingo in forum Reports
    Replies: 0
    Last Post: 06-25-2009, 09:17 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