Solved Multiple If Expression (1 Viewer)

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
Hi folks, I am trying to write a multiple-expression but do not know how to connect them properly. Help is appreciated.

=IIf(not IsNull( [CompleteDate] , "Complete", " ", IIf(IsNull( [ReviewDate] , "Not Started)," ", IIF( [DueDate] > Day(), "Inprocess","OverDue")))
 

Ranman256

Well-known member
Local time
Today, 14:31
Joined
Apr 9, 2015
Messages
4,337
rather that making messy nested IIFs , just make a custom function that reads cleaner:

usage:
=getResult( [CompleteDate], [ReviewDate], [DueDate])

Code:
Public Function getResult(pvCompDte, pvRevDte, pvDueDte)
Select Case True
   Case Not IsNull(pvCompDte)
       getResult = "Complete"
       
   Case IsNull(pvRevDte)
       getResult = "Not Started"
   
   Case pvDueDte > Date
       getResult = "Inprocess"
   
   Case Else
       getResult = "OverDue"
End Select
End Function
 

Mike Krailo

Well-known member
Local time
Today, 14:31
Joined
Mar 28, 2020
Messages
1,044
You had missing parentheses on your IsNull() functions and one parentheses that should have been a double quote.
=IIf(not IsNull( [CompleteDate] , "Complete", " ", IIf(IsNull( [ReviewDate] , "Not Started)," ", IIF( [DueDate] > Day(), "Inprocess","OverDue")))

Should Be:
Code:
=IIf(not IsNull( [CompleteDate] ), "Complete", " ", IIf(IsNull( [ReviewDate]) , "Not Started"," ", IIF( [DueDate] > Day(), "Inprocess","OverDue")))

I totally agree with Ranman256 on using his suggested function as it is so much easier to read.
 

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
You had missing parentheses on your IsNull() functions and one parentheses that should have been a double quote.


Should Be:
Code:
=IIf(not IsNull( [CompleteDate] ), "Complete", " ", IIf(IsNull( [ReviewDate]) , "Not Started"," ", IIF( [DueDate] > Day(), "Inprocess","OverDue")))

I totally agree with Ranman256 on using his suggested function as it is so much easier to read.
If I try this I get the wrong Number of arguments
 

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
rather that making messy nested IIFs , just make a custom function that reads cleaner:

usage:
=getResult( [CompleteDate], [ReviewDate], [DueDate])

Code:
Public Function getResult(pvCompDte, pvRevDte, pvDueDte)
Select Case True
   Case Not IsNull(pvCompDte)
       getResult = "Complete"
      
   Case IsNull(pvRevDte)
       getResult = "Not Started"
  
   Case pvDueDte > Date
       getResult = "Inprocess"
  
   Case Else
       getResult = "OverDue"
End Select
End Function
If I try this I I get
1696268717538.png
 

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
I have a glitch. The in-process date shows as Overdue. the Complete, Overdue, and Not Started statuses are working. The in in-process status is not working. It should show In process if the due date is greater than today.

Public Function getResult(CompleteDate, ReviewDate, DueDate)
Select Case True
Case Not IsNull(CompleteDate)
getResult = "Complete"

Case IsNull(ReviewDate)
getResult = "Not Started"

Case DueDate > Date
getResult = "OverDue"

Case Else
getResult = "In Process"
End Select
End Function
1696269890370.png
 

Attachments

  • Module Function Examples.accdb
    2.8 MB · Views: 52
Last edited:

plog

Banishment Pending
Local time
Today, 13:31
Joined
May 11, 2011
Messages
11,646
Read and understand Ranman's post, don't just skim and copy/paste half of it.
 

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
I have a glitch. The in-process date shows as Overdue. the Complete, Overdue, and Not Started statuses are working. The in in-process status is not working. It should show In process if the due date is greater than today.

Public Function getResult(CompleteDate, ReviewDate, DueDate)
Select Case True
Case Not IsNull(CompleteDate)
getResult = "Complete"

Case IsNull(ReviewDate)
getResult = "Not Started"

Case DueDate > Date
getResult = "OverDue"

Case Else
getResult = "In Process"
End Select
End Function
View attachment 110147
I Tried to add a line

Public Function getResult(CompleteDate, ReviewDate, DueDate)
Select Case True
Case Not IsNull(CompleteDate)
getResult = "Complete"

Case IsNull(ReviewDate)
getResult = "Not Started"

Case DueDate > Date
getResult = "OverDue"

Case DueDate < Date
getResult = "In Process"

Case Else
getResult = " "
End Select
End Function
 

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
I am sorry guys. I am having a hard time. I can not figure out how to write simple Expressions. I have read and watched videos on If statements and if I understand correctly there is supposed to be an expression, a True, and a false. I Wrote this but get too many arguments
=IIf(IsNull([CompleteDate], "","Complete")) Any suggestions on a sight where I could learn more?
 

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
I don't know what the Day() function is, does that have arguments?
I thought Day() called today's date
=IIf(not IsNull( [CompleteDate] ), "Complete", " ", IIf(IsNull( [ReviewDate]) , "Not Started"," ", IIF( [DueDate] > Day(), "Inprocess","OverDue")))
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:31
Joined
Sep 21, 2011
Messages
14,310
That would be Date()
What was wrong with the function offered?
 

Josef P.

Well-known member
Local time
Today, 20:31
Joined
Feb 2, 2023
Messages
826
Code:
=Switch(CompleteDate IS NOT NULL, "Complete", ReviewDate Is Null, "Not Started", DueDate > Date(), "Inprocess", DueDate <= Date(), "OverDue", True, "???")
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:31
Joined
Sep 21, 2011
Messages
14,310
Surely the False option is just another Iif until the last one?
 

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
Code:
=Switch(CompleteDate IS NOT NULL, "Complete", ReviewDate Is Null, "Not Started", DueDate > Date(), "Inprocess", DueDate <= Date(), "OverDue", True, "???")
I cannot get it to work correctly. The overdue date does not come in.
 

Attachments

  • Module Function Examples.accdb
    2.8 MB · Views: 54

Teri Bridges

Member
Local time
Today, 13:31
Joined
Feb 21, 2022
Messages
186
That would be Date()
What was wrong with the function offered?
I cannot Get the overdue to show correctly
Sorry I should have stated that the forms are not Done.

I am working with the Query 1 Query and the Query 1 Form. My bad.
When I get the statuses working correctly I was going to clean up. This is an excerpt of my read DB where I play to learn.
 

Attachments

  • Module Function Examples.accdb
    2.8 MB · Views: 47

Mike Krailo

Well-known member
Local time
Today, 14:31
Joined
Mar 28, 2020
Messages
1,044
I'm still trying to figure out why Ranman's function didn't work for you. You said you got a prompt for parameter getResult, but that doesn't make any sense. That function returns a string based on your three parameters. He gave you the exact usage.

I see from post #5 that you have a field in the table called Status, yet you are now trying to calculate the status in the query. If you are calculating the field in the query, you should not have a bound field called status. You cannot have a bound field called status and then try to alias it to status the way you did in the provided picture.
 

Users who are viewing this thread

Top Bottom