title: VBA: Type Mismatch
body: <p>I'm not particularly good at VBA yet. I am getting the error in the title pointing to the line that begins with <code>If NamePart =</code> and it's highlighting the <code>=</code> sign. Anyone know why?</p>
  
  <pre><code>Public Enum NamePart
      EnvironmentDefined
      FullName
      FirstName
      LastName
  End Enum
  
  Public Function GetUser(Optional ByVal part As NamePart = EnvironmentDefined) As String
  
      Dim result As String
      Dim sysInfo As Object
      Dim userInfo As Object
  
      If NamePart = EnvironmentDefined Then
          GetUser = Environ$("USERNAME")
          Exit Function
      End If
  
      Set sysInfo = CreateObject("ADSystemInfo")
      Set userInfo = GetObject("LDAP://" &amp; sysInfo.UserName)
      Select Case NamePart
          Case FullName
              result = userInfo.FullName
          Case FirstName
              result = userInfo.GivenName
          Case LastName
              result = userInfo.LastName
          Case Else
              result = Environ$("USERNAME")
      End Select
  
      GetUser = result
  
  End Function
  
  Private Sub Command363_Click()
  
      Call GetUser
      MsgBox "Username: " &amp; GetUser
  
  End Sub
  </code></pre>