I'm testing the script below.
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 & "\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
I am getting an error on this line:
Set MyRecordset = MyQueryDef.OpenRecordset
The error reads: Run-time Error '3219' Invalid Operation.
I think one of my references to an object is not being set correctly, but I really don't know what the problem is.
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?
Thanks!