Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IIF statement (2003)

    I have the following sample IIF Statement:

    =IIf(Environ$("UserName")="admin","Jimmy",IIf(Envi ron$("UserName")="admin2","Jimmy",IIf(Environ$("Us erName")="admin3","Tommy",Environ$("UserName"))))

    I just wondered if it was possible to shorten this up anyway?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: IIF statement (2003)

    Not really, but you could create a small user-defined function in a standard module:

    Public Function GetUser() As String
    Select Case Environ$("UserName")
    Case "admin", "admin2"
    GetUser = "Jimmy"
    Case "admin3"
    GetUser = "Tommy"
    Case Else
    GetUser = Environ$("UserName")
    End Select
    End Sub

    You can then use

    =GetUser()

    in your expression.

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: IIF statement (2003)

    It may not shorten it much, but you could use the SWITCH function which would perhaps make it easier to read:

    =Switch(Environ$("UserName")="admin","Jimmy",Envir on$("UserName")="admin2","Jimmy",Environ$("UserNam e")="admin3","Tommy",True,Environ$("UserName")

    The parameters within the parentheses are in pairs: condition, value. See VB Help for more details.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •