Solved

process filtered records - alternative

Posted on 2011-09-12
7
239 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

730 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