Sub InvokeStoredProcInAccess()
'NB: you'll have to set up the query in Access before you can use this!!
'Goto Access, and add the SQL needed. I'm using a PARAMETER query so that I can assign the values I need to add to each parameter
'The query in Access would be something like:
'"PARAMETERS [@Field1] Text, [@Field2] Text, [@Field3] Double;" & vbLf
'"INSERT INTO tblCtd ( Field1, Field2, Field3 )" & vbLf
'"SELECT [@Field] AS Expr1, [@Field] AS Expr2, [@Field] AS Expr3;"
'I saved the query with the name qryUpdateTable
'Here's how to invoke:
Dim l_qdfTmp As QueryDef
Dim l_dbDatabase As Database
Dim l_wsWorkSpace As Workspace
Dim l_wkbWorkbook As Workbook
Dim l_wksWorkSheet As Worksheet
Set l_wkbWorkbook = ThisWorkbook
Set l_wksWorkSheet = l_wkbWorkbook.Worksheets("NameOfSheet")
Set l_wksWorkSpace = DBEngine.CreateWorkspaces("Test", "admin", "", dbUseJet)
Set l_dbDatabase = l_wksWorkSpace.OpenDatabase("<FullPathAndFileName>")
Set l_qdfTmp = l_dbDatabase.QueryDefs("qryUpdateTable")
'Assign the values from the workbook to the parameters
l_qdfTmp.Parameters("@Field1") = l_wksWorkSheet.Range("A1")
l_qdfTmp.Parameters("@Field2") = l_wksWorkSheet.Range("B1")
l_qdfTmp.Parameters("@Field3") = l_wksWorkSheet.Range("C1")
'Run the query. Again, it's an action query so use EXECUTE
l_qdfTmp.Execute dbFailOnError
'Close & release objects
l_dbDatabase.Close
l_wsWorkSpace.Close
'Release objects
l_qdfTmp.Close
l_dbDatabase.Close
l_wsWorkSpace.Close
Set l_qdfTmp = Nothing
Set l_dbDatabase = Nothing
Set l_wsWorkSpace = Nothing
Set l_wkbWorksheet = Nothing
Set l_wkbWorkbook = Nothing
End Sub