title: Can't connect to Access Database from VBA query in Excel
body: <p>I have a VBA query built in excel that runs a SQL query against an Access Database. The connection works when the database is unprotected without a password using the following code:</p>
  
  <pre><code>Set Connection = New ADODB.Connection
  Cnct = "Provider=Microsoft.ACE.OLEDB.12.0;"
  Cnct = Cnct &amp; "Data Source=" &amp; DBFullName &amp; ";"
  Connection.Open ConnectionString:=Cnct
  </code></pre>
  
  <p>But when I password protect the database and try the same above but with added password condition, it won't connect and I get a "Run-time error -2147217843" message. The code I'm using for this is as follows:</p>
  
  <pre><code>Set Connection = New ADODB.Connection
  Cnct = "Provider=Microsoft.ACE.OLEDB.12.0;"
  Cnct = Cnct &amp; "Data Source=" &amp; DBFullName &amp; ";"
  Cnct = Cnct &amp; "user ID=" &amp; Environ("Username") &amp; ";"
  Cnct = Cnct &amp; "password=XXXXXXXXXX;"
  Connection.Open ConnectionString:=Cnct
  </code></pre>
  
  <p>Does anybody know what I am doing wrong here?</p>