[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 123
  • Last Modified:

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

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
Smilesxl
Asked:
Smilesxl
  • 3
  • 2
1 Solution
 
Dale FyeCommented:
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
 
SmilesxlAuthor Commented:
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
 
SmilesxlAuthor Commented:
Also, the field is a yes/no field, with a check box display control.  The field name is "PICK"
0
 
Dale FyeCommented:
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
 
SmilesxlAuthor Commented:
Awesome, thank you.  =)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now