Friday, November 4, 2016

Execute SQL stored procedure from Access 2010


  1. Create pass-through query in Access with any line of code, it doesn't matter because we will change this code before execution. call this query for example "PTQ"
  2.  Use the following VBA code, pay attention to a few details
    • ReturnsRecords must be set to False if the stored procedure dosen't return any records
    • Query "PTQ" must be a pass-through query, with a Connect property set properly


    Dim qdf As DAO.QueryDef
    Set qdf = CurrentDb.QueryDefs("PTQ")
    qdf.SQL = "exec myStoredProcedure '" & parameter & "'"
    qdf.ReturnsRecords = False
    qdf.Execute dbFailOnError

No comments: