Question

Using Auto Filtering and Enabling Checkbox Selection on Unbound Datasheet SubForms w/ SQL Server Backend

Asked by: n1ckjp

As you can see from the Title I'm trying to have my cake and eat it too.

I'm building a database in which there are two particular types of forms that I can see coming up over and over again and I'm trying to find a satisfactory way to use as much of the built-in access functionality while still maintaining a bit of flexibility and performance.

Currently I am using an Access 2007 accdb file backing onto a single SQL Server Express 2008 instance. I contemplated using an ADP and haven't completely thrown away the idea, but would need a fairly compelling reason to do so at this stage. (My initial experimentation seemed to indicate that Access 2007 doesn't yet have much in the way of SQLSrv2008 support which made me a bit leery)

The database is intended to track progress on work items and (among other things) provide an interface for supervisors to allocate said workitems to employees. The Work items have a fairly large number of attributes (columnns) which will need to be used to sort/filter the information.

I am quite new to SQL Server but have recently created a couple of views/stored procs/inline table-val functions to deal with much of the querying and am now reasonably confident working around the ADO library.

Unfortunately, I have discovered that binding ADO recordsets (during the form load procedure) to a Datasheet Form seems to disable all the built in Filter, Sort and Refresh functionality. I typically see a lot of "Data provider could not be initialized" type errors.

In some other scenarios I know I have managed to get the column header filters to work, but they are not populated with 'Lists of Values' for want of a correct term.

As a side note I have switched on the "Show List of Values in ODBC Fields" option

The two common forms I'm trying to build are:

1. A basic subform datasheet, that is 'linked' to its parent at the query level (rather than using a filter which seems to be a common method of handling this)

2 A subform in which numerous selections can be performed, the data sorted filtered, etc before performing an action on the selected list of rows.  

As a nice bonus it'd be good if I could use stored procedures to populate these forms as well, although that might be a bit of a stretch.

For Form type 1 I currently have in the On_load method of the parent form something like this:

Me.RecordSource = "SELECT * FROM uvw_PitemAllCategories WHERE PItemID =" & Me.OpenArgs
Me.chdAssign.Form.RecordSource = "SELECT * FROM uvw_Emp_Assignments WHERE PItemID=" & Me.OpenArgs

Which seems to work reasonably well, however I'd prefer to pass the select statement straight through to the SQL server since the two views (prefixed uvw_)  are likely to grow quite large over time and I don't want the whole thing being batted back and forth over the network.

For Form Type 2 I currently have gone down the path of designing a pile of custom classes built around an MSComctlLib.ListView control which I populate manually, however I'm not going to be able to come close to achieving the functionality of a basic Access datasheet in the timeframe required so am looking elsewhere.

One thought I'd had was to use the "Simple Select" method demonstrated by Leigh Purvis on his website ( http://www.databasedevelopment.co.uk/examples/ListSelect.zip ) (Great examples by the way Leigh. Incredibly helpful) but unfortunately my 'category table' is a non-updateable view which prevents me from selecting the checkboxes.

So anyway, I'm a bit stuck on where to go next and am worried about coding myself into a dead-end. 200 points for whoever can help me sort out Form problem 1 and 300 for Form problem 2. (and my undying gratitude)

Any general help or commentary on my design greatly appreciated.

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-10-15 at 22:33:09ID24817242
Tags

Access 2007

,

SQL Server 2008

Topics

Microsoft Access Database

,

Access Coding/Macros

,

MS SQL Server

Participating Experts
2
Points
500
Comments
7

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. .ADP Continuous Form (subform) based on server temp…
    I am creating my first ADP file in Access 2000/SQL Server 2000. I have a form with unbound controls that will be used to create records in several SQL Server tables. There is a one-to-many relationship between some of the fields on the main form and the fields I have on my ...
  2. Unbound Subform
    I have an Unbound Subform. Depending on user interaction, i assign a form to the Subform, which is based on a table dataset. Question: How do i capture what record the user is at when he/she scrolls through the DS (dataset.) brian thanks

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: LSMConsultingPosted on 2009-10-16 at 03:45:51ID: 25588248

"1. A basic subform datasheet, that is 'linked' to its parent at the query level (rather than using a filter which seems to be a common method of handling this)"

I'm not sure how you mean this, but you have two methods of handling this: Let Access do it through Master/Child links, or set the Recordsource/Recordset directly in an event of the Parent form. The method you choose depends on several factors, but unless you have a compelling need to do otherwise, let Access handle it.

"2 A subform in which numerous selections can be performed, the data sorted filtered, etc before performing an action on the selected list of rows.  "

You can perform whatever you wish on the form, but I'm not sure how that would translate over to your "action".

FWIW, You can use a Stored Procedure to return a Recordset, which you can then use to bind to your form:

Dim rst As ADODB.Recordset            
Set rst = New ADODB.Recordset

rst.Open "YourStoredProc", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Set Me.Recordset = rst

I have no idea about the "list of values" ...

In regards to the ADP item: you're better off with linked tables. Even MS has dropped support of the ADP format in the newer versions of Access (you can still run them, and even build them, but not if you're using the newer accdb format).

 

by: LPurvisPosted on 2009-10-16 at 06:30:46ID: 25589304

On the ADP front - I'd say it's a little unfair to say support for them has been dropped.
Moving to ACCDB isn't really applicable, as an ADP has always been a distinct file format. It used to be the alternative to MDB, now it's the alternative to ACCDB. Nothing's really changed on that front (the new data types in an ACCDB aren't applicable to SQL Server anyway).

(FWIW it's still quite a bit of effort for MS to implement support of ADPs in each new version. So they've not been forgotten about.)
It is true that MS, in general, advocate linked tables as the preferred data access mechanism. But, of course, many developers aren't listening to that.
It's hard to know when, or if, ADP's would be deprecated. I'd suggest that it will be when a viable Access functionality alternative is introduced.

Heh - I hadn't even noticed the reference to my examples until just now. You clearly have impeccable taste LOL.
Nah, seriously (it's sheer coincidence that I happened along actually) there are differences with an ADP. But there's pretty much always a workaround.

For example your errors attempting to manipulate the form's recordset.
In general, it's best to manipulate the recordset - and then re-apply it to the form. (There's little harm in maintaining the opened recordset still - it's the same memory object that the form is pointing to, just the overhead of another pointer).

On the non-updatable selection, it's true that joining to a non-update source will render the whole thing non-updatable.
There are ways around this of course. The later examples working with recordset binding mean you can always fill a different recordset with whatever values you see fit, present that to the user and then write back whatever selections you desire.
Obviously that's more effort than using default binding tricks - but once you leave Jet behind there are a few Access binding tricks that go out of the window.

Cheers.

 

by: n1ckjpPosted on 2009-10-18 at 03:15:06ID: 25599338

Thanks to both of you for your responses.

@ LPurvis: Seriously, those are some great examples on your site. I had a ball picking those apart and learnt some cool new tricks in the process.

Okay,
Form Type 1 - As I mentioned above I am currently setting the Recordsources of both the Parent and Child Form in the Parent Form on_load event. This seems to be one of the methods that you are suggesting LSM and if it's generally reasonable practice I'll keep doing it.

I like the idea of setting the WHERE clause of a query on-load (passing any keys via openargs as per my above code) and at the moment this seems to be working AND allowing me to use all the built-in access functionality such as the sort, refresh and drop-down filters ("list of values" I clumsily referred to previously.)

As an aside, do Master-Child Links function by using filters or queries? Perhaps my dislike of them is misplaced.

I like the added flexibility of being able to manipulate the recordsets myself, but I can live without it for this type of basic form. If there are no further suggestions regarding handling Form type 1 I'll leave it there.

As Form Type 2, the selection issue.

@ LSM - Sorry for my fuzzy explanation. I was trying to be too general. The 'Action' I referred to in this case would be assigning the selected list of Work Items to an employee (ala clicking an 'Assign' button).

The both of you seem to advocate manually assigning recordsets, (and I have seen your Shaped Recordset with Additional Field example here Leigh) but my problem here is that doing any sort of manual recordset assignment seems to fubar all the built-in sort, refresh, drop-down filter functionality. (In case It's not clear about what I'm referring to here I've attached an image of the filters at work.)

What I'm asking here is whether there is some way that either:

1. There is some way to dynamically add a nice selection checkbox column to an existing query/table (which will probably not be updateable) so that I can then offload all the recordset assignment to access (and then I will subsequently get all the aforementioned sort/filter functionality).

OR

2. There is some way to dynamically assign recordsets in such a way that the built in sort/filter functionality will still work and not generate "Data provider could not be initialized" errors. (This then allows me to use any one of a number of methods for handling selection)

OR

3. There is some way to override the sort/refresh/drop down filter functionality (by perhaps trapping events?) and either providing the access with whatever information that it's missing (and is causing the error previously mentioned), or creating my own procedures to handle the sort/filtering

OR

4. Something else??

 

by: LPurvisPosted on 2009-10-18 at 05:27:12ID: 25599602

First of all - thanks. I try to avoid the run-of-the-mill examples and show a somewhat different side of things.

Rather than address your specific questions, I have a couple of more general concepts to focus upon.
Firstly in response to your line:

>> As an aside, do Master-Child Links function by using filters or queries? Perhaps my dislike of them is misplaced.

Master Child links in Access are as much of a fundamental workhorse as subforms themselves.
They drive a vast majority of subforms included in applications.
However when you ask if they operate using filters or queries - I have to flag the concept that there isn't really a difference.

Certainly, through the UI in Access a filter appears to be a very different operation to a query. And by implementation, they often result in different actions. For example a filter often implies an existing set of displayed data which is "whittled down" by selecting a subset of those results. As implemented by default through the Access UI, the action a filter performs is actually making a request of the database to select only requested records. i.e. it executes a query. It just forms this query implicitly for you.

The term "filter" as a method of, say a DAO or ADO recordset probably aligns more as you would expect, reducing the contents of the recordset to only those which match the filter criteria. But in Access it's entirely possible to apply a filter as the data is loaded (the WhereCondition of an OpenForm method does this very commonly). The full data set is never retrieved (other than it's primary key index and any index required to query upon). Of course if you're querying (/filtering) upon fields which aren't indexed - then you're reading full tables anyway unless you're using a server database.
In this case you are - but you can't guarantee that server-side execution with linked tables without knowing what you're doing. (Have a look at the article here for a brief overview).

Using recordsets to drive your application and assigning them, almost inevitably, increases your development time - but it increases your control over the requested data. It's the halfway house between linked tables and going fully unbound.


>> doing any sort of manual recordset assignment seems to fubar all the built-in sort, refresh, drop-down filter functionality

Yes - it really does. It always has. The related example already mentioned would be that of Master/Child link fields. With assigned recordsets that has no effect and you're left to manually assign the subform recordset based on the foreign key value. Maintaining a full table recordset and filtering the recordset down to the required subset would be a poor choice in almost every database. (Unless you fully intended on visiting every single parent record - and even then it's a dodgy choice). Fetching the child set of records each time would be perfectly reasonable - and indeed what Access would do left to default functionality. (Remembering to consider what's mentioned above).

The other functionality, well - let's discuss that.
Much of Access convenient "Filter By Form" type functionality has, historically, been unavailable in Runtime installations. That immediately turns me off to it. However even more distasteful to me is the huge amount of data requests you're making to service that functionality. It's the age old choice of data convenience verses data efficiency.
It's nice for users to be able to get a distinct list of values from this field or that. But with each request comes (potentially) another heavy server data request. You can set filter by form to allow this search only on indexed fields - which will help - but you're then limiting user choices and I'd always rather do that guided searching through a dedicated search form (i.e. here are the fields by which you can search - enjoy!)

The development choice if assigning recordsets is designed to increase control and efficiency.
To want to combine that with the convenient in-form functionality is quite the contradiction of strategies.
I'm not saying that's why MS haven't implemented it for assigned recordsets - it is just inherently much more difficult to gather information about the schema of a source based on a recordset than a native or linked table about which Jet/ACE can make some fundamental assumptions.

Just as creating, loading and assigning the recordset is more effort - you'd also have to supply your own searching mechanisms. (i.e. a list which opens to offer distinct values of a field by which to limit). You'd control that call to the database, display that list to the user and then re-assign the recordset to the main form obeying the new criteria.

As I mentioned previously - your provider errors should be solved by not attempting to work with the assigned recordset - but work with a recordset object and then re-assign that recordset to the form.
The same applies to list controls for the most part.

Hope that's not all bad news for you. IMO much of client-server development (or even just applying client-server axioms to your Jet work) is in accepting that responsibility of being more lean and efficient with requests. And that in turn means doing more of the heavy lifting yourself in an ideal world.

Cheers.

 

by: n1ckjpPosted on 2009-10-18 at 19:38:01ID: 25602344

... Argh. Lost a whole post to a stray backspace key!

Thanks for taking the time to write such a clear explanationLeigh. Youve correctly picked up that I am grappling more with the designstrategy rather than specific code. (Although I find it is often easier to getanswers with specific code :P )

>> As implemented by default through the Access UI, theaction a filter performs is actually making a request of the database to selectonly requested records.

You have just harpooned one of my major assumptionsregarding filtering. As you suggest I had assumed that the UI treated drop-downfilters in a similar fashion that recordsets do (or at least the way I assumethey do... I dont actually have any evidence to back that up).

Thanks for the linkage, there are some good resources there.I read through your UApost and the linked post regarding SQLprofiler and ODBC Linked Tables and have come to the conclusion I need toget hold of a SQL profiler tool to test some of these assumptions. I only haveSQL express which doesnt come with a profiler sadly, however I see there is anopen source one available sowill give that a whirl.

To test your comment regarding Master/Child links. In myprevious code example where I assign both parent and child recordsources onform load:

Me.RecordSource = "SELECT * FROMuvw_PitemAllCategories WHERE PItemID =" & Me.OpenArgs
Me.chdAssign.Form.RecordSource = "SELECT * FROMuvw_Emp_Assignments WHERE PItemID=" & Me.OpenArgs<o:p></o:p>

If I understand you correctly, I wouldessentially achieve the same result with similar or better performance bysetting the Master and Child recordsources in design mode as uvw_PitemAllCategoriesand uvw_Emp_Assignments respectively. Then linking the Master/Child onPItemID and opening the form using the WhereCondition argument? <o:p></o:p>

I have a vague recollection that using theWhereCondition sets the filter property of the Parent form (and the UIindicates that a filter is in place) which is a little annoying since thiscan then be switched off or modified by the user, although I suppose one couldswitch off the navigation bar for the parent form and perhaps disable theribbon controls. (On going back to check this appears to be the case, however disablingfiltering on a parent form seems to also disable filtering on a subform as wellwhich kind of defeats my purposes anyway)<o:p></o:p>

>> Yes - it really does. It always has.

Oh well at least I know for sure and can let this one go. Iwas hoping maybe there was a secret handshake...

>> However even more distasteful to me is the hugeamount of data requests you're making to service that functionality.

Ah.. I can feel another incoming assumption-harpoon. Iconfess Id rather naively been working on the basis that the built in sortsand drop-down filters were implemented something like this:

  • <!--[if !supportLists]-->Client  Send server query. 
  • <!--[if !supportLists]-->Server  Return query results. 
  • <!--[if !supportLists]-->Client  Iterate through recordset generating alist of distinct values for each column. 
  • <!--[if !supportLists]-->Client  Populate column header dropdown listwith values. 

Then on a UI sort request

  • <!--[if !supportLists]-->Client  Locally sort the recordset and thenrefresh the view 

And on a UI drop-down filter selection

  • <!--[if !supportLists]-->Client  Locally apply a filter to the recordset(using the filter method) and refresh the view 

From what youre saying theres a lot more server requestsgoing on behind the scenes and if thats the case the built-in tools start tolook a lot less attractive.

>> Hope that's not all bad news for you

Actually not really. What you are suggesting is, to adegree, pointing me back in the direction I started going with my ListViewobject. This entire question is born out of my own concern that I was fallinginto the classic inexperienced-developer trap of reinventing the wheel.

In other words Why go to all the hassle of dealing with anon-standard Active X object and then writing a whole lot of code to implementbasic functionality like sorting, formatting and filtering when there is a richlyfeatured list-view (datasheet) already built into your development tool.

You seem to have pretty clearly answered that:

<!--[if !supportLists]-->1.      <!--[endif]-->I wont be able to use any of the manualrecordset manipulation and assignment tricks.

<!--[if !supportLists]-->2.      <!--[endif]-->The built in functionality generates a lot of serverrequests anyway.

Perhaps excessively over-simplified, but is that a fair interpretation?

 

by: n1ckjpPosted on 2009-10-18 at 19:39:55ID: 25602349

Sheesh... Note to self, don't try copy/pasting rich text posts from word. Bleaugh.

 

by: n1ckjpPosted on 2009-10-25 at 17:41:10ID: 31641983

This question was going a bit stale so thought it was time to close it. It's nudged me in what I believe is the right direction anyway

Thanks to both LSMConsulting and LPurvis for your answers and LPurvis for the useful discussion.

In hindsight I should probably have split these questions and asked them seperately and will do so in future.

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...