
Originally Posted by
John_G
In that statement, you are treating DLookup as if it returns a True / False. It doesn't - it returns a value if there is a record which matches the criteria, and it returns a Null otherwise.
You need to handle that Null with a Nz, something like this:
If nz(DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' "),"N/A") <> "N/A" Then
So it will execute the me!txtRTF = ... only if the DLookup does not return a Null, and the Nz does not yield a "N/A"
thanks for the help. it did work well, i changed the date calculation equation and it still works fine
Code:
Private Sub txtRTF_Click()
If Nz(DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' "), "N/A") <> "N\A" Then
Me.txtRTF = DateAdd("h", 2, [Date Fault Lodged])
End If
End Sub
i tried adding an else if statement i do not get an error however the elseif is not executed
Code:
Private Sub txtRTF_Click()
If Nz(DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' "), "N/A") <> "N\A" Then
Me.txtRTF = DateAdd("h", 2, [Date Fault Lodged])
ElseIf (DLookup("10_50", "SLA", "10_50 = '" & Me.cboSite.Value & " ' ")) Then
Me.txtRTF = DateAdd("h", 4, [Date Fault Lodged])
ElseIf (DLookup("50_80", "SLA", "50_80 = '" & Me.cboSite.Value & " ' ")) Then
Me.txtRTF = DateAdd("h", 8, [Date Fault Lodged])
ElseIf (DLookup("80_100", "SLA", "80_100 = '" & Me.cboSite.Value & " ' ")) Then
Me.txtRTF = DateAdd("d", 2, [Date Fault Lodged])
ElseIf (DLookup("Over100", "SLA", "Over100 = '" & Me.cboSite.Value & " ' ")) Then
Me.txtRTF = DateAdd("d", 10, [Date Fault Lodged])
End If
End If
End Sub