title: VBA running Access Query from Excel
body: <p>I am trying to run a VBA script that will Run and Export an Access query.  I'm able to get to the step in code where I run the query, however, I need to connect to DB2 to run this query in Access and I don't know how to implement into my code to enter the username and password.</p>
  
  <pre><code>Sub RunQuery()
  Dim A As Object
  Application.DisplayAlerts = False
  Set A = CreateObject("Access.Application")
  A.Visible = False
  A.OpenCurrentDatabase ("J:\user\filename.mdb")
  A.DoCmd.OpenQuery "QueryName"
  A.DoCmd.ConnectString
  Application.DisplayAlerts = True
  
  End Sub
  </code></pre>
  
  <p>The code just stalls at the line:</p>
  
  <pre><code>A.DoCmd.OpenQuery "QueryName"
  </code></pre>
  
  <p>And If I open my Database from here with my query it is just waiting for my username and password.  I'll try and attach a picture of the prompt.</p>
  
  <p>Any help would be greatly appreciated!!</p>
  
  <p>Thank you very much<a href="https://i.stack.imgur.com/EAmIZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EAmIZ.png" alt="enter image description here"></a></p>