Nested If

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

Is there a better way to code this statement? It works but I'm sure
there might be a better way.
Thanks
DS

Private Sub Image55_Click()
If IsNull(Me.TextD) Then
DoCmd.OpenForm "NoIDENTERED"
Else:
Dim vResult As Long
vResult = Nz(DLookup("[SignedIN]", "[Employees]", "EmployeeID=" &
Me.TextD & "And Active=" & -1), 7)

If vResult = 7 Then
DoCmd.OpenForm "InvalidID"
ElseIf vResult = -1 Then
If Me.TermType = 1 Then
DoCmd.OpenForm "Bar"
DoCmd.Close acForm, "ProServ"
ElseIf Me.TermType = 2 Then
DoCmd.OpenForm "DineIN"
DoCmd.Close acForm, "ProServ"
ElseIf Me.TermType = 3 Then
DoCmd.OpenForm "EatOut"
DoCmd.Close acForm, "ProServ"
End If
ElseIf vResult = 0 Then
DoCmd.OpenForm "NotSignedIN"
End If
End If
Me.Line16.Visible = False
Me.TextD = Null
End Sub
 
Looks okay to me (other than the fact that the indented isn't complete)

You could use a SELECT CASE rather than the multiple ElseIf if you wanted
to, but I don't think one's necessarily better than the other in this case.
 
Douglas said:
Looks okay to me (other than the fact that the indented isn't complete)

You could use a SELECT CASE rather than the multiple ElseIf if you wanted
to, but I don't think one's necessarily better than the other in this case.
Thanks, Feels good to do something Right !!!
DS
 
One may not be better than the other from an execution perspective; however,
the Select Case would be much easier to read.

Douglas J Steele said:
Looks okay to me (other than the fact that the indented isn't complete)

You could use a SELECT CASE rather than the multiple ElseIf if you wanted
to, but I don't think one's necessarily better than the other in this case.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


DS said:
Is there a better way to code this statement? It works but I'm sure
there might be a better way.
Thanks
DS

Private Sub Image55_Click()
If IsNull(Me.TextD) Then
DoCmd.OpenForm "NoIDENTERED"
Else:
Dim vResult As Long
vResult = Nz(DLookup("[SignedIN]", "[Employees]", "EmployeeID=" &
Me.TextD & "And Active=" & -1), 7)

If vResult = 7 Then
DoCmd.OpenForm "InvalidID"
ElseIf vResult = -1 Then
If Me.TermType = 1 Then
DoCmd.OpenForm "Bar"
DoCmd.Close acForm, "ProServ"
ElseIf Me.TermType = 2 Then
DoCmd.OpenForm "DineIN"
DoCmd.Close acForm, "ProServ"
ElseIf Me.TermType = 3 Then
DoCmd.OpenForm "EatOut"
DoCmd.Close acForm, "ProServ"
End If
ElseIf vResult = 0 Then
DoCmd.OpenForm "NotSignedIN"
End If
End If
Me.Line16.Visible = False
Me.TextD = Null
End Sub
 
Back
Top