title: Excel VBA querying from Password-Protected Access Database
body: <p>I am currently trying to query one of the table from Microsoft Access Database (.mdb), however, when I try to do a <code>SELECT * FROM myTable</code>, it gives an "User-defined type not defined". May I know why?</p>
  
  <p>Here's my sample code:</p>
  
  <pre><code>Private Sub CommandButton1_Click()
      Dim db As DAO.Database
      Dim dbPath As String
      Dim aQuery As String
      Dim pword As String
      Dim rs As DAO.Recordset
  
      dbPath = ThisWorkBook.Path &amp; "\Database.mdb"
      pword = "password"
      aQuery = "SELECT * FROM myTable"
  
      Set db = Access.DBEngine.Workspaces(0).OpenDatabase(dbPath, True, False, ";PWD=" &amp; pword)
      Set rs = db.Execute(aQuery)
      rs.MoveFirst
      MsgBox rs.Fields(0)
  
  End Sub
  </code></pre>