Results 1 to 5 of 5
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Help with if statement and date

    I'm trying to get a msgbox to appear in a form only if a date field is after a certain date. If the complaintdate is before 1/1/2022, I don't want the msgbox to appear. Below is my code, but it is not applying correctly. The msgbox appears regardless of the date. Any suggestions?



    Code:
    If ComplaintDate > "1/1/2022" Then msgbox "Message" End If

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Quote Originally Posted by templeowls View Post
    I'm trying to get a msgbox to appear in a form only if a date field is after a certain date. If the complaintdate is before 1/1/2022, I don't want the msgbox to appear. Below is my code, but it is not applying correctly. The msgbox appears regardless of the date. Any suggestions?

    Code:
    If ComplaintDate > "1/1/2022" Then msgbox "Message" End If
    Perhaps:
    Code:
    If ComplaintDate > CDate("1/1/2022") Then
       msgbox "Message" 
    End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    That worked!! Thanks so much!!

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    if a date field is after a certain date
    If it's really a date field, why pass a string to the logical test, only to convert it back to a date? Date data is delimited as #01/01/2022# If that wouldn't work, the field is text data type thus the conversion is needed.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Quote Originally Posted by templeowls View Post
    That worked!! Thanks so much!!
    Glad to help, if I can.

    Can I ask which "event" you are using and what kind of message you will be giving?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Help using iif and date add statement
    By mugsyronrox in forum Programming
    Replies: 3
    Last Post: 09-23-2020, 03:14 PM
  2. If statement with a date
    By UT227 in forum Programming
    Replies: 2
    Last Post: 02-01-2020, 09:24 PM
  3. =iff statement using date parameters
    By patchesohouli in forum Access
    Replies: 16
    Last Post: 07-19-2018, 11:12 AM
  4. Date Driven If statement in VBA
    By OverPlayed in forum Modules
    Replies: 4
    Last Post: 03-01-2018, 03:03 PM
  5. IIF statement using a date
    By elegant in forum Queries
    Replies: 1
    Last Post: 05-26-2011, 11:00 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