Results 1 to 4 of 4
  1. #1
    PBCN is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    24

    If ElseIf dependent on date

    Hi

    Ive got a if statement that calls a function dependent on a date in a field, but every time i click on it, it still calls function A even though the date is less than the date in the code below.

    I have used stop breaks and the date is showing up over the Me.DateApplicationReceived

    Any suggestions will be really appreciated.

    Code:
    If Me.DateApplicationReceived = Null Then
        Call A
    ElseIf Me.DateApplicationReceived >= "1/12/2019" Then
        Call A
    Else: Call B
    
    
    End If


  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Date values should be enclosed with #, not "
    eg

    Code:
    Me.DateApplicationReceived >= #1/12/2019#

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    to add to Orange's suggestion, the date needs to be the US format of mm/dd/yyyy

    1/12/2019 will be interpreted as 12th January

    Also, nothing can 'equal' null in vba, not even null=null, you need to use the isnull function

    If isnull(Me.DateApplicationReceived) Then



    edit: or you can use the nz function and simplify your code

    Code:
    If nz(Me.DateApplicationReceived,#1/12/2019#)  >= #1/12/2019# Then
        Call A
    Else
        Call B
    End If

  4. #4
    PBCN is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    24
    Awesome, thank you orange and ajax

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

Similar Threads

  1. If's with Elseif's
    By yeah in forum Programming
    Replies: 14
    Last Post: 05-17-2018, 07:07 AM
  2. Help with If...Then...ElseIf
    By willmafingerdo in forum Programming
    Replies: 2
    Last Post: 09-23-2016, 08:15 AM
  3. Replies: 7
    Last Post: 04-27-2016, 09:28 AM
  4. If then Elseif then....
    By Thompyt in forum Programming
    Replies: 3
    Last Post: 10-27-2014, 01:31 PM
  5. Dependent comboboxes and date picker
    By edmscan in forum Forms
    Replies: 4
    Last Post: 03-24-2014, 08:14 AM

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