title: Trying to Run Make Table Query in Access, from Excel
body: <p>I'm testing the script below.</p>
  
  <pre><code>Sub Update_All()
  
  Dim MyDatabase As DAO.Database
  Dim MyQueryDef As DAO.QueryDef
  Dim MyRecordset As DAO.Recordset
  Dim i As Integer
  
  'Step 2: Identify the database and query
  
  PathOfWorkbook = ThisWorkbook.Path
  FullPathOfAccess = PathOfWorkbook &amp; "\TRANSACTIONINFO.accdb"
  Set MyDatabase = DBEngine.OpenDatabase(FullPathOfAccess)
  Set MyQueryDef = MyDatabase.QueryDefs("TRANSBYMONTH")
  
  With MyQueryDef
  .Parameters("[StartDate]") = Worksheets("Date").Range("B9").Value
  .Parameters("[EndDate]") = Worksheets("Date").Range("B10").Value
  End With
  
  'Step 4: Open the query
  Set MyRecordset = MyQueryDef.OpenRecordset
  
  'MyQueryDef.Execute
  MyQueryDef.Close
  
  aa.DoCmd.SetWarnings WarningsOn:=True
  
  Set MyDatabase = Nothing
  Set MyQueryDef = Nothing
  
  ' Shut down reference to Access; clean up
  aa.Quit
  
  ' Refresh all links to Access
  ActiveWorkbook.RefreshAll
  
  End Sub
  </code></pre>
  
  <p>I am getting an error on this line:</p>
  
  <pre><code>Set MyRecordset = MyQueryDef.OpenRecordset
  </code></pre>
  
  <p>The error reads: Run-time Error '3219' Invalid Operation.</p>
  
  <p>I think one of my references to an object is not being set correctly, but I really don't know what the problem is.  </p>
  
  <p><a href="https://i.stack.imgur.com/rBpjR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rBpjR.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/YohNQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YohNQ.png" alt="enter image description here"></a></p>
  
  <p>I'm just trying to grab a StartDate and EndDate from 2 cells in Excel and pass both to a Make Table Query in Access.  How can I do that?</p>
  
  <p>Thanks!</p>