Solved

process filtered records - alternative

Posted on 2011-09-12
7
231 Views
Last Modified: 2012-05-12
This is a repeat of a question I raised earlier. I received a response and awarded points because I thought it would fix my problem but it hasn't. So I will restate the problem, state what I have done and why it doesn't work.

I need to create a mechanism that allows users to filter on a database and then I will write some code to process the selected records.

I have created a form that allows me to put some instructions, a "Select All" button and a "Process records" button in the header. I created a subform in datasheet view so that the user can use the standard MS Access filters to display the records they want to process, filtering on various fields as required.  Once they have displayed those records I want the user to be able to select which of the displayed records they want processed by checking the check box alongside each or by pressing the Select All button on the form. NB Each record has a field called Select, set to false when the form is first activated.

To handle the Select All functionality I tried the following code but it runs way too slow (7500 records takes about a minute to process), plus the form doesn't refresh properly when the process is finished. Can anyone help me figure out a solution?

Private Sub chkSelectAll_Click()
   Dim rs As Recordset
   On Error GoTo chkSelectAll_Click_Error
   Set rs = Me.sFrmSelectNurses.Form.Recordset
   
   rs.MoveFirst
   Do While Not rs.EOF
      If rs!SelectNurse <> Me.chkSelectAll Then
         rs.Edit
         rs!SelectNurse = Me.chkSelectAll
         rs.Update
      End If
      rs.MoveNext
   Loop
   rs.MoveFirst
   
   rs.Close
   Set rs = Nothing
   
   On Error GoTo 0
   Exit Sub

chkSelectAll_Click_Error:
    LogError Err.Number, Err.Description, "Form_frmBulkSMS", "chkSelectAll_Click", Erl
   Exit Sub
   Resume
End Sub
0
Comment
Question by:Rob4077
  • 4
  • 3
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
Comment Utility
This may be quicker...
Use an update query:

Dim strSQL as string
strSQL = "UPDATE YourTable SET SelectNurse = " & Me.chkSelectAll & " WHERE {use a where clause if you need to specify criteria}"
CurrentDB.execute strSQL, dbfailonerror
Me.Requery
0
 

Author Comment

by:Rob4077
Comment Utility
Thanks. Yes that would be faster but I need to only work with the records that have already been filtered on the form recordset and change those ONLY, not all records in the underlying table.
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
How are you filtering the records?

Are you using a string criteria (VBA) to select the needed records?

If so, you would apply that same critera as part f a WHERE clause.

In other words,

This statement
strSQL = "UPDATE YourTable SET SelectNurse = " & Me.chkSelectAll & " WHERE {use a where clause if you need to specify criteria}"

Open in new window


should look something like this:

strSQL = "UPDATE YourTable SET SelectNurse = " & Me.chkSelectAll & " WHERE " & strCriteria 

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Rob4077
Comment Utility
I am deliberately showing the subform in datasheet view so that the user can filter on any of the fields using the standard filter options. This gives maximum flexibility without me having to code all the possible options. When they've filtered to the point they're ready to go I want them to be able to process all the filtered records
0
 

Author Comment

by:Rob4077
Comment Utility
Although it didn't specifically answer the question your comment led me to the answer. I was able to get the filter description, change it from a form reference to a direct table reference and then use SQL on it to create the dataset that I needed. It works perfectly.

Thanks
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Good job working it out :)

My own next step would have been to ask to see a sample - I was having a tough time visualizing your setup.
0
 

Author Comment

by:Rob4077
Comment Utility
Turned out to be a lot easier than I thought. It's great now. I can let the user use the standard, powerful MS Access filter, check and uncheck the filtered items to come up with exactly the list they want and then I just process what's there. Thanks for your help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now