Results 1 to 3 of 3
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    If statement with a date

    I have a form with an unbound field [txtEndDate]. I have a button that if today's date is after this date, I want a message box to appear. I used this statement:
    If (txtEndDate < Date) Then
    MsgBox "Unable to delete"
    Then I tried to make another unbound field with today's date in it and use it in the code:
    If (txtEndDate < txtToday) Then
    MsgBox "Unable to delete


    Neither worked. The code just goes straight past it and into the ElseIf part of the code.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    The textbox date is just a string, not a true date value. Try:

    If CDate(txtEndDate) < Date Then

    But that will error if textbox is Null so try this:

    If CDate(Nz(txtEndDate,0)) < Date 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
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Perfect. Forgot about CDate. Dates always throw me off.
    Thank you

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

Similar Threads

  1. Date Driven If statement in VBA
    By OverPlayed in forum Modules
    Replies: 4
    Last Post: 03-01-2018, 03:03 PM
  2. IIF statement in Date calculations
    By wnicole in forum Access
    Replies: 1
    Last Post: 09-18-2013, 02:26 PM
  3. iif statement to generate date
    By Theremin_Ohio in forum Access
    Replies: 8
    Last Post: 05-31-2011, 07:52 AM
  4. IIF statement using a date
    By elegant in forum Queries
    Replies: 1
    Last Post: 05-26-2011, 11:00 AM
  5. ISO8601 Date in a IIF Statement
    By monkeyman in forum Queries
    Replies: 2
    Last Post: 05-23-2011, 12:16 PM

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