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

x
?
Solved

process filtered records - alternative

Posted on 2011-09-12
7
Medium Priority
?
244 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
[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
  • 4
  • 3
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

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