?
Solved

Access VBA:  Update a filtered subform based on the filter

Posted on 2013-01-16
3
Medium Priority
?
2,574 Views
Last Modified: 2013-01-16
Hi All

Big hairy question:  What's the VBA code to update ONLY the filtered rows in a subform?

Main form:  
A bunch of list boxes that allow users to select 'search' values.
GO command button that filters a subform based on VBA that pieces together a filter.
   Example:  [state] = 'CA' AND [products] IN ('bananas', 'grapes')
Select all command button that checks the 'is_selected' checkbox for all rows in the subform.

Subform:  
Starts with all records in an updateable SQL view (say 1,000), which includes a bit (Yes/No) column with a checkbox called is_selected that users can check or uncheck.
The main form's GO command button filters the form via VBA, displays the filtered records, and does not update them.
The main form's Select All command button checks the is_selected checkbox in all rows in the subform.

My task is to write VBA so that the Select All button ONLY checks the is_selected checkbox for the rows that have been filtered.  Using the above example, if CA bananas and grapes amount to 200 of the total 1,000 rows, then I want those 200 is_selected checkboxes checked, and the others unaffected.

Thanks in advance.
Jim
0
Comment
Question by:Jim Horn
[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
3 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 600 total points
ID: 38782627
is the  "is_selected checkbox" bound or unbound ?

if bound

sql="update [subformtable] set is_selected=-1 where " & form_subformName.filter
0
 
LVL 61

Accepted Solution

by:
mbizup earned 1400 total points
ID: 38782675
Jim,

If your subform filter contains constraints for fields in different tables (not just the table you are updating), it might be easiest to use recordset code:

dim rs as DAO.recordset
set rs = Me.SubformName.form.recordsetclone

if rs.recordcount = 0 then exit sub

Do until rs.EOF
      rs.edit
      rs![is_selected] = true
      rs.update
      rs.movenext
Loop
set rs = nothing
Me.SubformName.form.requery

Open in new window

0
 
LVL 66

Author Closing Comment

by:Jim Horn
ID: 38784432
Both solutions work, but the loop enables me to make SQL SP calls individually, so that was accepted as best.  Thanks.  -Jim
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

765 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