If...then...else

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have put this code into the afterupdate event of the field [dept] and I
want to populate [subdept]. What is wrong with the following code?

If Me.Dept = "ALS" Then Me.Subdept = "ALS"
ElseIf Me.Dept = "Finance" Then Me.Subdept = "Finance"
ElseIf Me.Dept = "Process Team" Then Me.Subdept = "Process Team"
Else me.subdept = Null

thanks
 
When there are few If's I rather use "Select case", it's easier to understand
and maintain if you need to add another If

Select Case Me.Dept
Case "ALS" , "Finance" , "Process Team"
Me.Subdept = Me.Dept
Case Else
me.subdept = Null
End Select
 
Nice short hand.

thanks


Ofer Cohen said:
When there are few If's I rather use "Select case", it's easier to understand
and maintain if you need to add another If

Select Case Me.Dept
Case "ALS" , "Finance" , "Process Team"
Me.Subdept = Me.Dept
Case Else
me.subdept = Null
End Select

--
Good Luck
BS"D


scubadiver said:
I have put this code into the afterupdate event of the field [dept] and I
want to populate [subdept]. What is wrong with the following code?

If Me.Dept = "ALS" Then Me.Subdept = "ALS"
ElseIf Me.Dept = "Finance" Then Me.Subdept = "Finance"
ElseIf Me.Dept = "Process Team" Then Me.Subdept = "Process Team"
Else me.subdept = Null

thanks
 
scubadiver said:
I have put this code into the afterupdate event of the field [dept] and I
want to populate [subdept]. What is wrong with the following code?

If Me.Dept = "ALS" Then Me.Subdept = "ALS"
ElseIf Me.Dept = "Finance" Then Me.Subdept = "Finance"
ElseIf Me.Dept = "Process Team" Then Me.Subdept = "Process Team"
Else me.subdept = Null

You're missing an End If. Also, as Ofer Cohen pointed out, this looks like
a
job for Select Case.

Tom Lake
 
I knew there was something missing but select case is far simpler.


Tom Lake said:
scubadiver said:
I have put this code into the afterupdate event of the field [dept] and I
want to populate [subdept]. What is wrong with the following code?

If Me.Dept = "ALS" Then Me.Subdept = "ALS"
ElseIf Me.Dept = "Finance" Then Me.Subdept = "Finance"
ElseIf Me.Dept = "Process Team" Then Me.Subdept = "Process Team"
Else me.subdept = Null

You're missing an End If. Also, as Ofer Cohen pointed out, this looks like
a
job for Select Case.

Tom Lake
 
Back
Top