Solved

process filtered records - alternative

Posted on 2011-09-12
7
234 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
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.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

786 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