none
AutoNew macro with If xxxx or xxxxx then conditional statment RRS feed

  • Question

  • Small piece of code that simply does not work. I need to limit access to a word template so this code to check for who is currently logged in to the machine should do it?? right??  When I step through this code it always sets the true bit and goes to the MsgBox. Even when I switch up the logic the result is the same. Any help is appreciated.

    Glenn

    Current user is Glenn.

    Sub AutoNew()

    Dim WhoAreYou as String

    WhoAreYou = (Environ$("Username"))

    If Not WhoAreYou = "John" Or Not WhoAreYou = "Glenn" Then

    MsgBox "You Are Not Allowed To Use This Form!"

    ActiveDocument.Close wdSaveChanges = False

    End

    End If

    End Sub


    Glenn

    Sunday, December 8, 2013 2:58 PM

Answers

  • Change the line

    If Not WhoAreYou = "John" Or Not WhoAreYou = "Glenn" Then

    to

    If Not WhoAreYou = "John" And Not WhoAreYou = "Glenn" Then

    or, equivalently,

    If WhoAreYou <> "John" And WhoAreYou <> "Glenn" Then


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Chevyman57 Sunday, December 8, 2013 7:18 PM
    Sunday, December 8, 2013 3:24 PM

All replies

  • Change the line

    If Not WhoAreYou = "John" Or Not WhoAreYou = "Glenn" Then

    to

    If Not WhoAreYou = "John" And Not WhoAreYou = "Glenn" Then

    or, equivalently,

    If WhoAreYou <> "John" And WhoAreYou <> "Glenn" Then


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Chevyman57 Sunday, December 8, 2013 7:18 PM
    Sunday, December 8, 2013 3:24 PM
  • Hans,

    Thanks a much, worked great.

    I guess my logic was getting scrambled in my pea brain and the more I looked at it the worse it got.

    Glenn


    Glenn

    Sunday, December 8, 2013 7:20 PM