Configuring an Access report to use a SQL Server stored procedure as its record source

前端 未结 1 1386
没有蜡笔的小新
没有蜡笔的小新 2021-01-20 18:55

I\'m trying to create a report in MS Access 2010 with results of MS SQL Server Stored Procedure. In my VBA code I try:

Dim qdf As DAO.QueryDef
Set qdf = Curr         


        
相关标签:
1条回答
  • 2021-01-20 19:20

    Create a saved pass-through query in Access that executes your stored procedure. In this example I'll call the named query [myPassThroughQuery].

    Edit your report to make myPassThroughQuery the Record Source for the report.

    Now you can tweak the SP call before opening the report:

    Dim cdb As DAO.Database, qdf As DAO.QueryDef
    Set cdb = CurrentDb
    Set qdf = cdb.QueryDefs("myPassThroughQuery")
    qdf.SQL = "EXEC spMyProc @ID = " & "1"
    Set qdf = Nothing
    Set cdb = Nothing
    DoCmd.OpenReport "mySpReport", acViewPreview
    
    0 讨论(0)
提交回复
热议问题