Solved

process filtered records - alternative

Posted on 2011-09-12
7
238 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
ID: 36521893
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
ID: 36523459
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
ID: 36523664
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:Rob4077
ID: 36526666
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
ID: 36528705
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
ID: 36528727
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
ID: 36528897
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

837 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