Results 1 to 5 of 5
  1. #1
    wardw is offline Advanced Beginner
    Windows 7 64bit Access 2000
    Join Date
    May 2013
    Location
    Hines, Oregon
    Posts
    41

    How to compare dates in two form fields

    In Access 2000, I'm trying to validate two fields containing dates. The date 1PublicationDate field must be later than the date in the DeathDate field, so I'm using an OnChange event on the 1PublicationDate field.

    When I make a change in that field, Visual Basic shows this error: "Run-time error '2465': Microsoft Access can't find the field '|' referred to in your expression."



    I'm using this code:
    Code:
    Private Sub FirstPublicationDate_Change()
    
    If DateDiff("d", [Me.DeathDate], [Me.1PublicationDate]) < 0 Then GoTo Err_FirstPublicationDate_Change
    
    Exit_FirstPublicationDate_Change:
        Exit Sub
    
    Err_FirstPublicationDate_Change:
        MsgBox "First Publication Date must be same as or later than Death Date."
    End Sub
    The bold portion is what VB highlights in debug mode.

    Where's the error in my syntax, or is there a simpler way to validate the dates?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Try the AfterUpdate event instead of Change

    And:

    If Me.1PublicationDate < Me.Deathdate Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    June7's advice about using the AfterUpdate event, instead of the OnChange event, is dead on, because the OnChange fires with each character that is entered, not after all data is entered, but it won't solve your problem!

    According to the posted code. the Control is named

    Private Sub FirstPublicationDate_Change()

    But you code refers to a Control named

    1PublicationDate

    which, I suspect, is the field that Access cannot find!

    Linq ;0)>

  4. #4
    wardw is offline Advanced Beginner
    Windows 7 64bit Access 2000
    Join Date
    May 2013
    Location
    Hines, Oregon
    Posts
    41
    Thanks for your help, June7 and Linq. I changed to AfterUpdate and fixed the name discrepancy, and now all is well.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>

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

Similar Threads

  1. Compare dates in vba
    By rjbautista20 in forum Programming
    Replies: 1
    Last Post: 08-17-2012, 09:44 AM
  2. Replies: 1
    Last Post: 02-17-2012, 04:43 PM
  3. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  4. Compare two fields
    By funkygoorilla in forum Programming
    Replies: 2
    Last Post: 01-18-2012, 09:43 PM
  5. Compare two fields!
    By finditsol in forum Forms
    Replies: 1
    Last Post: 02-11-2010, 01:43 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