Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Multiple Recordsets to Turn Filter On/Off

Posted on 2012-04-05
3
Medium Priority
?
253 Views
Last Modified: 2012-04-16
Uisng Access 2007, with libraries for DAO:
 - Microsoft Office 12.0 Access database engine Object Library
 - Microsoft Jet and Replication Objects 2.6 Library

On a form, I've put radio buttons/option group to select two different modes.

Mode1 - browse/edit all records in a table, sorted by ID (i.e.Primary Key). As a row is edited and saved, the userid and date/time-saved are both stored into two extra columns on the row.  Then use Back and Next buttons to move to previous/next row.

Mode2 - edit only rows which have not already been processed ( i.e. userid and date/time-saved columns are NULL).  When switching from Mode1 to Mode2, note current position, then when switched to Mode2, position goes to FIRST row where ID.Mode2 > ID.Mode1 (i.e. the "next" unedited row.)

I've currently implemented this with one recordset.  Switching to Mode2 is done with:
   
    Dim sSQL As String
    sSQL = "([USER_EDIT] IS NULL) AND ([USER_SAVE] IS NULL)"
    DoCmd.ApplyFilter whereCondition:=sSQL

Open in new window


Switching back to Mode1 is done with:
Me.FilterOn = False

Open in new window


Using this code, wherever I'm positioned in the recordset becomes the beginning of the sorted subset (i.e. any un-saved rows with [ID] < currentID will not appear in the rows for Mode2.)  In addition, the sort order changes completely .. can't really identify if there is one.  

It would seem that using two recordsets (rst1 and rst2), using the existing definition as is for rst1, then adding the sort and filter criteria to rst1 and create a second recordset via
set rst2 = rst2.OpenRecordset

Open in new window

should work.. but I can't get the last statement to work... it says I have missing parameters for the OpenRecordset method.

The other thing that bothers me about this code is that I'm using a DoCmd.ApplyFilter to do the select, but then do a Me.FilterOn to reverse the operation.  What's DoCmd got to do with it, and what is "Me" referring to when it's used to turn off the filter?

Being new to Access VBA, I'm not clear on how these recordsets relate to the form.  I see what appears to be a "default" recordset named RECORDSET, and somehow the fields on the form are bound to the columns in this recordset.  At a conceptual level, if I could "swap" the recordsets bound to the form, then I could switch back and forth based on the desired mode.

Since conceptual does not match practical in many instances, what's the best way to get this done?

Thanks
0
Comment
Question by:MiltonLClark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37813180
???

If I am reading your post correctly, ...I am not quite sure why you need recordsets for this...?

Why not simply post a sample DB, so we can eveluate your design?

Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Remove any records unless they are relevant to the issue.
5. Delete any objects that do not relate directly to the issue.
6. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
7. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
8. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
9. Compile the code. (From the VBA code window, click: Debug-->Compile)
10. Run the compact/Repair utility.
11. Remove any Passwords and/or security.
12. If a form is involved in the issue, set the Modal and Popup properties to: No
    (Again, unless these properties are associated with the issue)
13. Post the explicit steps to replicate the issue.
14. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see and/or troubleshoot the issue.
And if applicable, also include a clear graphical representation of the *Exact* results you are expecting, based on the sample data.

JeffCoachman
0
 

Accepted Solution

by:
MiltonLClark earned 0 total points
ID: 37814031
A solution was found by a colleague... it had to do with assigning a 0-length string to the column instead of a NULL .. the missing rows were elided because they were not null, they had a 0-length string in them.

I'm keeping these steps handy in the event I need to post here again.

Thanks for the help.
0
 

Author Closing Comment

by:MiltonLClark
ID: 37850339
As stated in the comment, the solution was provided by a colleague, not by EE Expert.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question