Question

Access 2007: Altering a Recordset or Record Source for a Report based on an ADO stored procedure.

Asked by: Stewiedoo

Hello,

I have an Access 2007 front end app, (Accdb not ADP) that uses ADO connections to access tables and stored procedures on a SQL Express 2008 server.

Everything appears to be fine except for one known issue with this setup, and I've been unable to locate a solution.

I have a report, that has groups, and would like to set the recordset or record source of the report on Form Load.

It would appear that Access 2007 does not let me change a reports recordset unless it's an ADP, and I cant use the record source property as the SP is not in the Access front end.

I have managed to make it work, but I have had to create an ODBC connection to the database, and then create a Pass-Through query to the database, and use that as the record source, but I thought it was a little untidy to create and ODBC connection just for reports.

Is there a way that I can do this from VBA code, my thoughts being to open an ADO recordset, and then print/group the report on the fly?

I am unable to change the recordset at all, as it errors with a 'Only allowed from and ADP' error.

It should be mentioned that it is intended to convert this to a 'web based' solution at some point, hence the reason for wanting to have as little happening within the Access front end as possible.

Thank you for your assistance.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-25 at 10:42:58ID24762507
Tags

Access 2007

,

Recordset

,

Record Source

,

ADO

,

Stored Procedure

Topics

Microsoft Access Database

,

VB Database Programming

,

Access Reports

Participating Experts
4
Points
500
Comments
14

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ADO
    Is ADO a completly new language? Is there much to it?
  2. Connect to an ADP using ADO...
    Hi there... I'm having a horrible time getting data out of my SQL Server. I need a completely flexible, 100% code-based method of extracting data into a text file or Access table, but none seem to exist (that don't have significant setbacks). DTS's require front-end setup in ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Helen_FeddemaPosted on 2009-09-25 at 10:52:26ID: 25425375

I am not sure whether this would be helpful, since I am using DAO rather than ADO, but here is the technique I use to create a filtered recordset on-the-fly, and then you can use either the strSQL variable, or the temp query created by the code, as the record source for a form or report, or you can create a recordset from the SQL for use elsewhere in code:

[sample code fragment using the procedure]
 
   Dim dbs As DAO.Database
   Dim lngCount As Long
   Dim lngID as Long
   Dim rst As DAO.Recordset
   Dim strPrompt As String
   Dim strQuery As String
   Dim strRecordSource As String
   Dim strSQL As String
   Dim strTitle As String
   
   strRecordSource = "tblInventoryItemsComponents"
   strQuery = "qryTemp"
   Set dbs = CurrentDb
 
   'Numeric filter
   lngID = Me![ID]
   strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _
      & "[ID] = " & lngID & ";"
 
   'String filter
   strInventoryCode = Me![InventoryCode]
   strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _
      & "[InventoryCode] = " & Chr$(39) & strInventoryCode & Chr$(39) & ";"
 
   'Date range filter
   dteFromDate = CDate(GetProperty("FromDate", ""))
   dteToDate = CDate(GetProperty("ToDate", ""))
   strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _
      & "[dtmDateReceived] Between " & Chr(35) & dteFromDate _
      & Chr(35) & " And " & Chr(35) & dteToDate & Chr(35) & ";"
 
   Debug.Print "SQL for " & strQuery & ": " & strSQL
   lngCount = CreateAndTestQuery(strQuery, strSQL)
   Debug.Print "No. of items found: " & lngCount
   If lngCount = 0 Then
      strPrompt = "No records found; canceling"
      strTitle = "Canceling"
      MsgBox strPrompt, vbOKOnly + vbCritical, strTitle
      GoTo ErrorHandlerExit
   Else
      Set rst = dbs.OpenRecordset(strQuery)
   End If
 
=========================
 
Public Function CreateAndTestQuery(strTestQuery As String, _
   strTestSQL As String) As Long
'Created by Helen Feddema 28-Jul-2002
'Last modified 13-Aug-2008
 
On Error Resume Next
   
   Dim qdf As DAO.QueryDef
   
   'Delete old query
   Set dbs = CurrentDb
   dbs.QueryDefs.Delete strTestQuery
 
On Error GoTo ErrorHandler
   
   'Create new query
   Set qdf = dbs.CreateQueryDef(strTestQuery, strTestSQL)
   
   'Test whether there are any records
   Set rst = dbs.OpenRecordset(strTestQuery)
   With rst
      .MoveFirst
      .MoveLast
      CreateAndTestQuery = .RecordCount
   End With
   
ErrorHandlerExit:
   Exit Function
 
ErrorHandler:
   If Err.Number = 3021 Then
      CreateAndTestQuery = 0
      Resume ErrorHandlerExit
   Else
      MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
      Resume ErrorHandlerExit
   End If
   
End Function
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:

Select allOpen in new window

 

by: StewiedooPosted on 2009-09-25 at 11:43:15ID: 25425929

Hello Helen, thank you for your prompt response.

The problem I have is not creating a recordset, I can do that without much problem using ADO. The problem exist in seting this recordset or it's record source as that of the Report.

Accdb's do not allow you to change a recordset, you have to be creating an ADP, so something like:

report.Recordset = myRst

does not work, and to change the record source you need to have the SQL string, which I dont have for the ADO recordset as it's been created by executing a stored procedure.

Hence the current work around, to create pass-through query on an ODBC connection, then I can use:

SELECT * qryPassThrough WHERE parameter

as the record source.

 

by: boag2000Posted on 2009-09-25 at 12:02:06ID: 25426113

 

by: StewiedooPosted on 2009-09-25 at 12:42:17ID: 25426548

Hello boaq200, I got quite excited there as this is very similar to what I was doing except I was omiting the 'SET' and I thought that was the difference.

Alas, that is not so, and even though I have tried what he is written, and that was nearly my original approach, I still get the error 'This feature is only available in an ADP'

 

by: LSMConsultingPosted on 2009-09-25 at 13:47:15ID: 25427101

I was incorrect in my other post. I had mixed my environments, and in fact you cannot do this unless you're working in an ADP.

The next best solution is temporary tables, IMO.

 

by: StewiedooPosted on 2009-09-25 at 13:53:47ID: 25427157

Hello LSM, thank you for visiting this thread.

So are you suggesting that I create a table from the ADO recordset On Load, and set that as the Record Source to the report?

Would you consider that to be a 'better' solution to the one I have currently found, which is to create and ODBC connection to the DB, and then use a Pass-Through query as the Record Source.

The obvious question is, how will both of these sit, if at all, with a future ASP deployment of the solution, and should I be looking at Reporting Services instead as a long term solution?

 

by: LPurvisPosted on 2009-09-26 at 05:03:31ID: 25429581

Hello.

To be honest, even in an ADP report recordset binding isn't all it could (/should?) be.
Binding forms to recordsets has been available since Access 2000. That reports still lag behind points to just how differently they work, but ultimately they still just source data (that they may read it repeatedly needn't be a problem - especially in a client side recordset).

Passthroughs (as you're already using) are actually a common (and not untidy) implementation for sourcing reports with server objects. Passthroughs are, by definition, read only - which makes them great for reporting (no unecessary overhead to support updatability which isn't required). Of course this assumes that you're not using subreports in any way (as, unlike subforms, will alsmot always be linked to the parent and then passthroughs can't be used as your source. Access simply refuses. We wait with baited breath on that score...)

Filling a local table then becomes your next step (as Scott mentioned).
However doing so from a passthrough (or two) is a relatively nice, easy set based operation.
Doing so from a recordset is, inevitably, iterative in nature. This takes time.
Parse an ADO recordset with a few thousand rows in it and you'll feel it. On a modern, beefed-up PC not very much hopefully - but it'll be there.

Your goal of moving to a web application (I assume you're talking about a non-Access web app here?) isn't really related to this issue as I see it.
You've implemented the SP which fuels this request. That will also be the source which you connect to online. While you're in Access you'll use Access functionality to read that SP on the server. Which method you use in Access isn't really relevant to your eventual online implementation.
I see nothing wrong with the Passthrough as it stands. If, for some reason, you were experiencing poor ODBC performance on your PC/Network then you could perhaps tackle that itself if OLEDB via ADO is scorchingly faster that local table is still an option.

When you mention that you're having to "create an ODBC connection to the DB", by that do you mean you're creating a DSN?
Access will establish (and maintain :-s) the ODBC connection to the server. All you need to provide is an appropriate connection string for the Passthrough query to use. Such a connection string is no harder to form than the OLEDB one you're likely using in ADO.

Show your Passthrough creating code if you're unsure.
But it's something like the attached snippet?

Cheers.

Function fCreatePassThrough(strName As String, strSQL As String, strDBname As String, _
                        strServer As String, Optional blnIntegratedSecurity As Boolean, _
                        Optional strUserName As String, Optional strPassword As String, _
                        Optional blnReturnsRecords As Boolean = True, Optional strDriver As String = "{SQL Server}")
    
    Dim db As Database
    Dim qdf As QueryDef
    Dim strConnect As String
    
    strConnect = "ODBC;Driver=" & strDriver & ";Server=" & strServer & ";Database=" & strDBname
    If blnIntegratedSecurity Then
        strConnect = strConnect & ";Trusted_Connection=Yes"
    Else
        If Len(strUserName) > 0 And Len(strPassword) > 0 Then
            strConnect = strConnect & ";UID=" & strUserName & ";PWD=" & strPassword
        End If
    End If
    
    Set db = CurrentDb
    Set qdf = db.CreateQueryDef(strName)
 
    With qdf
        .ReturnsRecords = blnReturnsRecords
        .connect = strConnect
        .SQL = strSQL
        .ODBCTimeout = 60
        .Close
    End With
    
    Set qdf = Nothing
    Set db = Nothing
    
End Function

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:

Select allOpen in new window

 

by: StewiedooPosted on 2009-09-26 at 06:33:29ID: 25429803

Hello

Thank you for your response.

I think you have put my mind at easy regarding Passthrough queries. I thought that, as I was trying to keep all data sources/definitions etc. outside of Access, that this was untidy, I was unaware that this was actually a valid solution for what I was trying to achieve. I think I need to look at Reporting Services for when I create the Web App, and you are right it won't be Access, but probably ASP. I have already created the report in Reporting Services, and it works, but I need to iron out the damn accessing permissions complications that I am having trying to display/manage report within reporting services (but that's a different topic!).

Thank you for your snippet, but I am actually defining the Passthrough directly query builder, by simply using the same SQL that it in the original SP, and then using a WHERE clause to cater for the funtionality of the SP's parameters.

I would like to offer some token points to Jeffery for leading me to Scott's post, and some to Scott for following my email to this thread and confirming things. The rest I will offer you Leigh, for putting my mind at rest and confirming that I am in fact moving in the right direction.

Thank you all for your comments.

 

by: LPurvisPosted on 2009-09-26 at 07:43:07ID: 25429948

No worries, altering the definition of an existing PT is perfectly normal. As long as you didn't jump through any hoops to create it in the first place (i.e. creating a DSN). The function above can make that initial creation easier. (Using it repeatedly would cause file growth as the PTs are created and destroyed. Of course an open PT can't be deleted and locks can occur.).

Cheers.

 

by: StewiedooPosted on 2009-09-26 at 08:02:15ID: 25430004

Sorry I did forget to answer that point, I did in fact create a System DSN for the Passthrough, as you saying that I should not have? This was the thing that made the solution seem untidy, I was creating an ODBC connection (System DSN entry) simply for reports.

 

by: LPurvisPosted on 2009-09-26 at 08:16:07ID: 25430044

Exactly. There's no need for that.
Creating a DSNless ODBC string is very simple (that earlier function does exactly that when you pass the necessary parameters describing the server, database etc).

Cheers.

 

by: StewiedooPosted on 2009-09-26 at 08:53:02ID: 25430150

Ah ok, so I basically add something like that to my sqlOperations Class, and call that to create the Passthrough on the fly as and when I need it.

Thanks

 

by: LPurvisPosted on 2009-09-26 at 16:41:01ID: 25432070

Once it's been created with the DSNless connection stirng, you can operate as you were just changing the definition.
You can just insert the new connection string into your existing PT query if you want. Creating the string is all that's really required.

 

by: StewiedooPosted on 2009-09-26 at 17:26:05ID: 25432197

Ok, got it, working a treat.

Thank you.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...