Write a function and use a Case statement. Pass in the controls/variable if not in the module that needs them.
If needed in more than one place, put into a stamdard module, else leave it in the form module, then you will not need to pass in the controls/variables
It will also be much much easier to read.
=IIF(Me.D2 = "Not Required in Current FY","No Visit Required",
IIF((Me.A2 <> DATE() AND Me.B2 =""),"Needs Scheduled",
IIF(ISNUMERIC(Me.B2) AND Me.C2 =""),"Work Scheduled ",
IIF(Me.C2 = Me.B2,"Completed",
IIF(Me.C2 <= Me.B2,"Completed Earlier",
"Completed with Delay")))))
Hi Wleshgasman, thank for your help i will try my best to see if I can make it work for meI generally do not write code for people, just because it takes me a while to write it, I am not a developer doing it day in, day out, just an amateur.
However also because people do not learn anything if it is handed to them on a plate, they just come back for more, like Oliver.
However to make the minimum changes.
Replace IF with IIF
Replace your cell references with your control/field values
I have made an attempt, where I used similar control names so you can see what goes where. Hopefully you will have more meaningful names for your controls.
Code:=IIF(Me.D2 = "Not Required in Current FY","No Visit Required", IIF((Me.A2 <> DATE() AND Me.B2 =""),"Needs Scheduled", IIF(ISNUMERIC(Me.B2) AND Me.C2 =""),"Work Scheduled ", IIF(Me.C2 = Me.B2,"Completed", IIF(Me.C2 <= Me.B2,"Completed Earlier", "Completed with Delay")))))
HTH
'***************************
' https://www.techonthenet.com/access/functions/advanced/isnumeric.php
' https://www.techonthenet.com/access/functions/date/date.php
' https://www.techonthenet.com/access/functions/index.php
'***************************
Sub test_doit()
Dim field_A As Variant
Dim field_B As Variant
Dim field_C As Variant
Dim field_D As Variant
field_A = Date
field_B = "23"
field_C = "abc"
field_D = "def"
Dim retval As String
retval = doit(field_A, field_B, field_C, field_D)
Debug.Print (retval)
MsgBox (retval)
End Sub
'***************************
Function doit(field_A, field_B, field_C, field_D)
Dim s As String
If field_D = "Not Required in Current FY" Then
s = "No Visit Required"
ElseIf field_A <> Date And field_B = "" Then
s = "Needs Scheduled"
ElseIf IsNumeric(field_B) And field_C = "" Then
s = "Work Scheduled"
ElseIf field_C = field_B Then
s = "Completed"
ElseIf field_C <= field_B Then
s = "Completed Earlier"
Else
s = "Completed with Delay"
End If
doit = s
End Function
'***************************