Results 1 to 3 of 3
  1. #1
    Hirex is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2016
    Posts
    3

    Access 2010 - SQL Server - Subreport with Stored Procedure

    Hello,

    I'm working with Access 2010 and SQL Server 2014.

    I have a problem with report and sub report which were based on an SQL Server stored procedure.
    Main report works perfect.

    Problem is with subreport.
    I have seen on Google search that I can't work with stored procedure on a sub report (this only work with ADP). Must use subform instead.

    I have added the following code on the Open Event of the subform.

    Private Sub Form_Open(Cancel As Integer)
    Dim cmd As New adodb.Command
    With cmd
    .ActiveConnection = cn
    .CommandText = "pr_myStoredProc"
    .CommandType = adCmdStoredProc
    .Parameters.Refresh
    .Parameters("@EndDate") = Forms!frmForm!TbxEndDate
    Set Me.Recordset = cmd.Execute
    End With
    Set cmd = Nothing


    End Sub

    "Link Master Fields" and "Link Child Fields" are set to a field named "CustomerSiteID", which is a part of the main report.

    As a result, my sub form never give me records.

    Could you help me please ?
    Many thanks in advance.
    Chris.

  2. #2
    Hirex is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2016
    Posts
    3
    It seems that the better solution is to create a local temp table in Access based on the stored procedure "pr_myStoredProc".

    Sub Report must have a query as record source which reads the local temp table.
    Then set "Link Master Fields" and "Link Child Fields" to CustomerSiteID to make Access doing its job.

    On the "OnActivate" event of the main report, you run the stored procedure and fill the temp table. Don't forget to delete the table before filling it.

    For remember, to delete a table with a query you have to call :
    currentdb.execute "qryDeleteTempTable", assuming the query looks like : DELETE tblTemp.* FROM tblTemp;

    Hope this help.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Thanks for posting your solution. I typically use the local table in these situations too.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Stored Procedure in MS Access 2007
    By sels1987 in forum Access
    Replies: 1
    Last Post: 05-13-2012, 12:23 PM
  2. Replies: 3
    Last Post: 03-20-2012, 10:00 AM
  3. Execute MySQL Stored Procedure with Access 2010 VBA?
    By DanielHofer in forum Programming
    Replies: 5
    Last Post: 01-23-2012, 01:08 PM
  4. creating Stored Procedure in Access 2007
    By shraddha in forum Access
    Replies: 5
    Last Post: 08-03-2010, 09:43 AM
  5. Replies: 3
    Last Post: 05-23-2010, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums