Solved

Select All records in a filtered continuous form selection from single check box

Posted on 2013-01-04
11
1,365 Views
Last Modified: 2013-05-01
Good morning,

I have a working form which I use to filter data and update various fields on a form.  I want the option to "select all" records which would be populated in the detail of the form.

Does the underlying table have to have a check box field for me to perform a "select all" or can the check box on the detial line be some kind of unbound field...something that an update query could still refer to?

I hope I am clear on my issue.  If not, please ask for clarification and I'll do what I can to accomodate.

Thanks,
MC
0
Comment
Question by:MCaliebe
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 39

Expert Comment

by:als315
Comment Utility
You should give more details about process. Usually one unbound checkbox in header is enough.
0
 

Author Comment

by:MCaliebe
Comment Utility
I have an unbound check box in the header of the form..which we call chk_SelectAll.  I would like it, when clicked, to Select or Deselct all records in the form detail.  i will need to add a check box to each detail record so an update query could make changes based on whether or not the detail check box is true or false.

Does the check box in the detail need to be part of the table being updated or can it remain unbound in the detail.

I know how to fire an update query from an unbound check box in the header to update all records in a table to true, which should in turn repopulate a check box in the detail of the form to true...provided it is linked to that table field.

I just imagine that there should be a way to flag which records in the detail need to be updated without actually having to first rewrite a true/false field in each record of the table.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
You did not state how you were filtering this form, but in the most basic sense you can cancel out any filters with code like this:

Me.Filter=""
Me.FilterOn=False

...and this will display all records

Now, if the Recordsouce of the form itself is filtering the records, you may want to post a simple sample of this database, to avoid confusion.

JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
We still need to know how you are filtering the form.

This is why a sample database makes things easier to understand.

Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Remove any records unless they are relevant to the issue.
5. Delete any objects that do not relate directly to the issue.
6. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
7. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
8. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
9. Unhide any hidden database objects
10. Compile the code. (From the VBA code window, click: Debug-->Compile)
11. Run the compact/Repair utility.
12. Remove any Passwords and/or security.
13. If a form is involved in the issue, set the Modal and Popup properties to: No
    (Again, unless these properties are associated with the issue)
14. Post the explicit steps to replicate the issue.
15. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see and/or troubleshoot the issue.
And if applicable, also include a clear graphical representation of the *Exact* results you are expecting, based on the sample data.

JeffCoachman
0
 
LVL 39

Expert Comment

by:als315
Comment Utility
It is clear now. Unbound box in detail will not be related to your record, so you should have field in table (in separate table, may be).
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 61

Accepted Solution

by:
mbizup earned 175 total points
Comment Utility
For what you are describing, the checkbox in your detail section needs to be bound to a field in the underlying table.  (Create a boolean field called isSelected)

This will select all records in your subform's recordset, regardless of filtering.  I'm assuming the code will be placed behind your unbound "Select All" checkbox on the main form.

Dim rs as DAO.recordset
SET rs = Me.SubformControlName.Form.recordsetClone
if rs.recordcount = 0 then 
     msgbox "No records present"
     exit sub
end if
do until rs.eof

rs.edit
rs!isSelected = true
rs.update
rs.movenext

Loop
set rs = nothing
 Me.SubformControlName.Form.Requery

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
<It is clear now. >
Yes, for me to as well...

it seems like mbizup has got you covered here...

;-)

Jeff
0
 

Author Comment

by:MCaliebe
Comment Utility
Thank you for everyones advice.  My initial question, do I have to have a bound check box in the deteail has been answered completely.  Because I wanted my selections limited to the filtered items, I am using the following code to fire off my slection properties.

Private Sub Chk_Select_All_Click()
Dim stSQL As String

'If gcfHandleErrors Then On Error GoTo PROC_ERR


If Not Me.txt_filterStr = "" Then


    If Me.chk_select_all = True Then
        DoCmd.SetWarnings False
        stSQL = "UPDATE (tbl_EOS_Rank INNER JOIN TBL_OAUSER_INV_MASTER " & _
                "ON tbl_EOS_Rank.ITEM_SEQUENC_NO = TBL_OAUSER_INV_MASTER.ITEM_SEQUENC_NO) LEFT JOIN tbl_Excl_Item_Numbers " & _
                "ON TBL_OAUSER_INV_MASTER.ITEM_SEQUENC_NO = tbl_Excl_Item_Numbers.ITEM_SEQUENC_NO SET tbl_EOS_Rank.Select = True " & _
                "WHERE " & Me.txt_filterStr
                
        DoCmd.RunSQL stSQL
        Me.Refresh
        
        Else
        stSQL = "UPDATE (tbl_EOS_Rank INNER JOIN TBL_OAUSER_INV_MASTER " & _
                "ON tbl_EOS_Rank.ITEM_SEQUENC_NO = TBL_OAUSER_INV_MASTER.ITEM_SEQUENC_NO) LEFT JOIN tbl_Excl_Item_Numbers " & _
                "ON TBL_OAUSER_INV_MASTER.ITEM_SEQUENC_NO = tbl_Excl_Item_Numbers.ITEM_SEQUENC_NO SET tbl_EOS_Rank.select = False " & _
                "WHERE " & Me.txt_filterStr
                
        DoCmd.RunSQL stSQL
        Me.Refresh
        DoCmd.SetWarnings True
    End If
Else
MsgBox ("Please apply filter before selecting ALL items")
Me.chk_select_all = False

End If

'PROC_ERR:
  'MsgBox "Error: (" & Err.Number & ") " & Err.Description, vbCritical

End Sub

Open in new window


My only issue at this time is I get a write failure/conflict if I do a Select All, and then go into the detail and deselect some items.

Is there a way to prevent this?
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 175 total points
Comment Utility
The Select All checkbox in your main form should be *unbound*.  You only need a bound checkbox in the detail section.

Also add this line to the Enter event of your subform control:

Me.Refresh
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Also... if you are using SQL Server for a back-end, ensure that the isSelected Bit field has its Allow Nulls property set to False and has a default value of (0).
0
 

Author Closing Comment

by:MCaliebe
Comment Utility
Thanks to everyone for your input.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now