If...then...else

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
 
G

Guest

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
 
G

Guest

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
 
T

Tom Lake

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top