After Update help needed

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

Guest

I have a field, named "LastName" on a form. The After_Update is set to the
following: (it basically removes from view certain fields which don't need to
be filled in, depending upon whether "Conference" is entered in the LastName
field, or "Break," "Lunch" or "Fine!")

Private Sub LastName_AfterUpdate()
If Me.LastName = "Conference" Then
Me.Level.Visible = False
Me.FirstName.Visible = False
Me.Combo178.Visible = False
Me.Box219.Visible = False
Me.Label180.Visible = False
Me.Honors.Visible = False
Me.ExamType = "Conf"
Else: Me.Level.Visible = True
Me.FirstName.Visible = True
Me.Combo178.Visible = True
Me.Box219.Visible = True
Me.Label180.Visible = True
Me.Honors.Visible = True
End If

If Me.LastName = "Break" Or Me.LastName = "Lunch" Or Me.LastName =
"Fine!" Then
Me.Level.Visible = False
Me.FirstName.Visible = False
Me.Combo178.Visible = False
Me.Box219.Visible = False
Me.Label180.Visible = False
Me.Honors.Visible = False
Me.ExamType.Visible = False
Me.Fee.Visible = False
Else: Me.Level.Visible = True
Me.FirstName.Visible = True
Me.Combo178.Visible = True
Me.Box219.Visible = True
Me.Label180.Visible = True
Me.Honors.Visible = True
Me.ExamType.Visible = True
Me.Fee.Visible = True
End If

End Sub

Interestingly, the behavior is working properly, but only if "Break",
"Lunch" or "Fine!" is entered in the last name field. It seems to be
bypassing the opening If...Then routine.

What did I miss?

Thanks in advance.

Jerry
 
Interestingly, the behavior is working properly, but only if "Break",
"Lunch" or "Fine!" is entered in the last name field. It seems to be
bypassing the opening If...Then routine.

Nope. It's executing the first IF, setting everything the way you
want. Then it's executing the second IF, and since "Conference" is not
equal to "Break", "Lunch", or "Fine!", it's executing the ELSE
statements, undoing everything that the first IF did.

Just a suggestion: using special values of the LastName field is
probably not good design. A field in a table should be "atomic" and
"homogenous" - having some values treated differently can get you into
complexity and confusion. For example, suppose someone typed in
"Confereance" - it would just be loaded as a lastname, and both IF's
would take the False branch. I would suggest some other control
(perhaps an unbound combo box) to let the user *select* one of these
four options, rather than misusing the LastName field in this way.

John W. Vinson[MVP]
 
Try code like:
SELECT CASE Me.LastName
Case "Conference"
Me.Level.Visible = False
Me.FirstName.Visible = False
Me.Combo178.Visible = False
Me.Box219.Visible = False
Me.Label180.Visible = False
Me.Honors.Visible = False
Me.ExamType = "Conf"
Case "Break", "Lunch","Fine!"
Me.Level.Visible = False
Me.FirstName.Visible = False
Me.Combo178.Visible = False
Me.Box219.Visible = False
Me.Label180.Visible = False
Me.Honors.Visible = False
Me.ExamType.Visible = False
Me.Fee.Visible = False
Case Else
Me.Level.Visible = True
Me.FirstName.Visible = True
Me.Combo178.Visible = True
Me.Box219.Visible = True
Me.Label180.Visible = True
Me.Honors.Visible = True
END SELECT
You might also want to rename some controls so that your code "makes sense".
 
The Else section of the second If statement will trample all over anything
that's been set in the first If statement.

You need a structure such as:
If Me.LastName = "Conference" Then
...
Else
If Me.LastName = "Break" Or Me.LastName = "Lunch" Or Me.LastName =
"Fine!" Then
...
Else
...
End If
End If

Or, alternatively, consider using a Select Case structure:
Select Case LastName
Case "Conference"
...
Case "Break", "Lunch", "Fine!"
...
Case Else
...
End Select

HTH,

Rob
 
Back
Top