I have a macro in Excel that refreshes several of the queries in my DB. i need to add to it a command that will refresh an Append query in the same DB. i know you cant do this through the ODBC link. is there another way?
I am just seeing if there is a way to run an Append query in Access from a macro in Excel.
I need the records to be stored in an Access table before i can run the rest of my macro.
Function RunAppendQuery(strDatabaseName As String, strAppendQueryName As String)
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = OpenDatabase(strDatabaseName)
Set qdf = db.QueryDefs(strAppendQueryName)
qdf.Execute
qdf.Close
db.Close
Set qdf = Nothing
Set db = Nothing
End Function
And you pass the name of the database and the query to it like:
Oh, and you'll have to use this in a MODULE (don't name it the same as the function) in your Excel File and you will need to set a reference to Microsoft DAO 3.x (where x is a number like 51 or 6).
"(strDatabaseName As String, strAppendQueryName As String)"
is called the Input Parameters. So this is what you use when you want code to be "reusable" (in other words you don't have to specify at the time you design it what objects it will work on). You PASS these parameters at runtime when you CALL the function.
So you do NOT change that at all. You pass the database path and name and the query name at the place you are CALLING it.
As for setting a reference to DAO you go into the VBA Window and then up to TOOLS > REFERENCES and then scroll down the list until you see
MICROSOFT DAO 3.x Object Library (and if you have 3.6 listed pick that, if not pick the 3.51) then close the dialog and you are set.
ok, i got everything working great. but i have one more small issue.
i would like to be able to run the Call to the append query, and then only run the rest of the module when the append query in access is finished. any ideas? thanks again, hopefully you are still subscribed to this thread...