"IF" code needed (1 Viewer)

Matizo

Registered User.
Local time
Today, 14:38
Joined
Oct 12, 2006
Messages
83
Hello, I am looking for a code that will be showing the status of the work I’ve got.
I have 4 text boxes on the form: StartDate ; EndDate ; CurrentDate and WorkStatus. The StartDate and EndDate are linked to the tblWorks.
As the default value for CurrentDate I have =Date() .
I need a code that will do something like this:

If

StartDate < CurrentDate and EndDate < CurrentDate THEN WorkStatus = “Work Done”

If

StartDate < CurrentDate <= EndDate THEN WorkStatus = “Work In Progress”

If

StartDate > CurrentDate THEN WorkStatus = “FutureWork”

Thanks in advance,
 

KeithG

AWF VIP
Local time
Today, 14:38
Joined
Mar 23, 2006
Messages
2,592
Something like below should work

IIF([Start Date]<Date(),IIF([End Date]<Date(),"Work Done","Work In Progress"),"Future Work")
 

Matizo

Registered User.
Local time
Today, 14:38
Joined
Oct 12, 2006
Messages
83
Thanks! I used that in my query and it works:)
But I still would appreciate if you could give me the VB code for my form.
Thanks again!
Matt
 

KeithG

AWF VIP
Local time
Today, 14:38
Joined
Mar 23, 2006
Messages
2,592
You can put the expression as the control source of a textbox. Are you saying you want to create a function to do this? Why does this expression not suite your needs?
 

Matizo

Registered User.
Local time
Today, 14:38
Joined
Oct 12, 2006
Messages
83
Hi,

The expression you gave me is great and I am going to use it anyway I just wonder to find out what the function for that is. The use of “Case statement”.

Thanks a lot!,
Regards

Matt
 

MarkK

bit cruncher
Local time
Today, 14:38
Joined
Mar 17, 2004
Messages
8,199
Code:
Function GetStatusText(dStart As Date, dEnd As Date) As String
   Select Case Date
      Case Is < dStart
         GetStatusText = "Future"
      Case Is > dEnd
         GetStatusText = "Past"
      Case Else
         GetStatusText = "Current"
   End Select
End Function
 

Users who are viewing this thread

Top Bottom