title: VBA: Login using Windows Authentication
body: <p>I have a an Access App that requires the user to enter their Windows domain user and password to enter. I have used the following VBA code to accomplish this:</p>
  
  <pre><code>Function WindowsLogin(ByVal strUserName As String, ByVal strpassword As String, ByVal strDomain As String) As Boolean
      'Authenticates user and password entered with Active Directory. 
  
      On Error GoTo IncorrectPassword
  
      Dim oADsObject, oADsNamespace As Object
      Dim strADsPath As String
  
      strADsPath = "WinNT://" &amp; strDomain
      Set oADsObject = GetObject(strADsPath)
      Set oADsNamespace = GetObject("WinNT:")
      Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strDomain &amp; "\" &amp; strUserName, strpassword, 0)
  
      WindowsLogin = True    'ACCESS GRANTED
  
  ExitSub:
      Exit Function
  
  IncorrectPassword:
      WindowsLogin = False   'ACCESS DENIED
      Resume ExitSub
  End Function
  </code></pre>
  
  <p>I notice that sometimes when the information is entered correctly, access is denied. I tried to debug once and it gave the error: "The network path was not found.
  " on the <code>Set oADsObject = oADsNamespace.OpenDSObject)</code> line.</p>
  
  <p>Not sure why this occurs sometimes. Is it better to convert to LDAP instead? I have tried but can't construct the LDAP URL correctly.</p>