?
Solved

Form based on a table with a check box field, need select all

Posted on 2015-01-08
5
Medium Priority
?
119 Views
Last Modified: 2015-01-09
I have a table that opens in a form, it is a list of parts in an inventory database.  I use it to relieve inventory for an assembly when we are pulling parts from the crib to build.  You need to select the parts in the assembly you are pulling, most of the time you want to select all, there are times when you would pick only a few parts.  I would like a button at the top of the form "Select All", would be nice if you hit it a second time, it "Un-Selects All".  This is a field in a table.  I tried to attach query to the button, but then I will have to refresh the form etc..  Looking for the best way to do it.  I am using MS Access 2013.
0
Comment
Question by:Smilesxl
[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
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 40538580
easiest way is to write a query.  I have a button cmd_Select which has a caption which changes after each click.

Private Sub cmd_Select_Click

    Dim bSelect as Boolean
    Dim strSQL as string

    bSelect = (me.cmd_Select.Caption = "Select All")
    strSQL = "UPDATE [yourTable] SET [YourField] = " & bSelect
    currentdb.execute strsql, dbfailonerror
    me.cmd_Select.Caption = iif(bSelect, "Un-select All", "Select All")
    me.refresh   ' refreshes the form

End Sub

Open in new window

0
 
LVL 2

Author Comment

by:Smilesxl
ID: 40539355
That didn't work, tried this and this didn't work either.
Private Sub SelectAll_Click()
    Dim bSelect As Boolean
    Dim strSQL As String

    bSelect = (Me.SelectAll_Click.Caption = "Select All")
    strSQL = "UPDATE [Part List] SET [PICK] = Yes"
    CurrentDb.Execute strSQL, dbFailOnError
    Me.SelectAll_Click.Caption = IIf(bSelect, "Un-select All", "Select All")
    Me.Refresh   ' refreshes the form

End Sub
0
 
LVL 2

Author Comment

by:Smilesxl
ID: 40540003
Also, the field is a yes/no field, with a check box display control.  The field name is "PICK"
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 40540037
Yes/No fields are boolean and should accept True/False as well as -1/0 as values
This should work:

Private Sub cmd_Select_Click

    Dim bSelect as Boolean
    Dim strSQL as string

    'This line determines the caption of the Select button at the current time
    bSelect = (me.cmd_Select.Caption = "Select All")
    
    'The next two lines should update the field
    strSQL = "UPDATE [Part List] SET [Pick] = " & bSelect
    currentdb.execute strsql, dbfailonerror

    'Change the caption
    me.cmd_Select.Caption = iif(bSelect, "Un-select All", "Select All")

    'refreshes the form
    me.refresh   

End Sub

Open in new window

0
 
LVL 2

Author Closing Comment

by:Smilesxl
ID: 40540097
Awesome, thank you.  =)
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

800 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