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

x
?
Solved

Access VBA:  Update a filtered subform based on the filter

Posted on 2013-01-16
3
Medium Priority
?
2,649 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

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