Howto set Access Recordsource onto a "select" sproc

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Radu

    Howto set Access Recordsource onto a "select" sproc

    Hi. I have lots of processing to do on the server - from the client
    (Access) I call a sproc which returns a recordset (the sproc is
    essentially a big "select"). With the obtained data , I need to
    generate a report. How do I set the Recordsource of the report to the
    result of the select sproc ?

    I have tried the following, but it does not work.

    Private Sub cmdReport_Click ()

    On Error GoTo cmdReport_Click Error

    Dim objCmd As ADODB.Command
    Dim intOpenObjects As Integer
    Dim rsTemp As ADODB.Recordset

    Set objCmd = New ADODB.Command
    intOpenObjects = 1

    objCmd.ActiveCo nnection = m_objConn
    objCmd.CommandT ype = adCmdStoredProc
    objCmd.CommandT ext = "_TestRepor t"

    Set rsTemp = objCmd.Execute
    intOpenObjects = 2

    Dim rpt As Report
    DoCmd.OpenRepor t "TestReport ", acViewDesign
    Set rpt = Reports("TestRe port")
    Set rpt.RecordSourc e = rsTemp
    DoCmd.Close acReport, "TestReport ", acSaveYes
    Set rpt = Nothing
    DoCmd.OpenRepor t "TestReport ", acViewPreview

    DoCmd.OpenRepor t "TestReport ", acViewPreview
    DoCmd.SelectObj ect acReport, "TestReport "
    DoCmd.Maximize

    cmdReport_Click Exit:
    If intOpenObjects = 2 Then
    rsTemp.Close
    Set rsTemp = Nothing
    intOpenObjects = 1
    End If
    If intOpenObjects = 1 Then
    Set objCmd = Nothing
    intOpenObjects = 0
    End If

    Exit Sub

    cmdReport_Click Error:
    MsgBox Err.Description , vbCritical, Me.Name
    Resume cmdReport_Click Exit
    End Sub

    How can I do that, please ? Would it maybe be better to change the
    "Select" sproc into an Insert sproc, as in "SELECT... INTO TEMP", in
    order to create a temp table on the server, then in Access link to that
    table and set the recordsource onto the linked table ?

    Please help. Thank you very much, Alex.

  • Simon Hayes

    #2
    Re: Howto set Access Recordsource onto a "select&qu ot; sproc

    You'll probably get a better response in one of the
    microsoft.publi c.access.* groups - how to present data in an Access
    report isn't really an MSSQL question.

    Simon

    Comment

    • Stu

      #3
      Re: Howto set Access Recordsource onto a "select&qu ot; sproc

      Look at pass-through queries in Access; they'll run the stored
      procedure on SQL Server. However, you'll have to use VBA to modify the
      paramaters (by actually modifiying the text of the pass-through query).

      Stu

      Comment

      • nicolec@octitle.com

        #4
        Re: Howto set Access Recordsource onto a "select&qu ot; sproc

        If you are using a data project (ADP), you simply name the recordsource
        the name of the stored procedure, either hard coded in the report
        designer or in code at runtime.

        If you are using an MDB, Stu's suggestion of pass-through query objects
        is the usual method.

        Radu wrote:[color=blue]
        > Hi. I have lots of processing to do on the server - from the client
        > (Access) I call a sproc which returns a recordset (the sproc is
        > essentially a big "select"). With the obtained data , I need to
        > generate a report. How do I set the Recordsource of the report to the
        > result of the select sproc ?
        >
        > I have tried the following, but it does not work.
        >
        > Private Sub cmdReport_Click ()
        >
        > On Error GoTo cmdReport_Click Error
        >
        > Dim objCmd As ADODB.Command
        > Dim intOpenObjects As Integer
        > Dim rsTemp As ADODB.Recordset
        >
        > Set objCmd = New ADODB.Command
        > intOpenObjects = 1
        >
        > objCmd.ActiveCo nnection = m_objConn
        > objCmd.CommandT ype = adCmdStoredProc
        > objCmd.CommandT ext = "_TestRepor t"
        >
        > Set rsTemp = objCmd.Execute
        > intOpenObjects = 2
        >
        > Dim rpt As Report
        > DoCmd.OpenRepor t "TestReport ", acViewDesign
        > Set rpt = Reports("TestRe port")
        > Set rpt.RecordSourc e = rsTemp
        > DoCmd.Close acReport, "TestReport ", acSaveYes
        > Set rpt = Nothing
        > DoCmd.OpenRepor t "TestReport ", acViewPreview
        >
        > DoCmd.OpenRepor t "TestReport ", acViewPreview
        > DoCmd.SelectObj ect acReport, "TestReport "
        > DoCmd.Maximize
        >
        > cmdReport_Click Exit:
        > If intOpenObjects = 2 Then
        > rsTemp.Close
        > Set rsTemp = Nothing
        > intOpenObjects = 1
        > End If
        > If intOpenObjects = 1 Then
        > Set objCmd = Nothing
        > intOpenObjects = 0
        > End If
        >
        > Exit Sub
        >
        > cmdReport_Click Error:
        > MsgBox Err.Description , vbCritical, Me.Name
        > Resume cmdReport_Click Exit
        > End Sub
        >
        > How can I do that, please ? Would it maybe be better to change the
        > "Select" sproc into an Insert sproc, as in "SELECT... INTO TEMP", in
        > order to create a temp table on the server, then in Access link to that
        > table and set the recordsource onto the linked table ?
        >
        > Please help. Thank you very much, Alex.[/color]

        Comment

        Working...