Consulting

Results 1 to 7 of 7

Thread: 1 click ticks 4 rows

  1. #1
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location

    1 click ticks 4 rows

    Hi People,

    On a form I have datasheet, on this datasheet there is also a column of checkbox's (data type Yes/No).
    There are 4 rows for each 'record', when I click any of the checkbox's it should place a tick in all rows in the 'record' in this column of checkbox's (data type Yes/No).
    Also, if I uncheck the box, all rows uncheck.
    Column P has the unique identifier that shows what rows belong to what record.They are grouped together, i.e. ordered list.
    So each tick I place in a check box, 4 rows should be ticked, based on the value in Column P.
    It will always be 4 rows, as the unique value in column P is repeated for each 4 rows.

    Thanks,

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    Use a update query.

    currentdb.execute "update YourTable set SomeField = " & CheckBoxValue & " where ColumnP = " & ColumnP
    me.requery

  3. #3
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Thanks jonh.
    But not quite what I was after.

    If I open Table1 and click any Tickbox in first column then any same ColumnP rows should also be ticked. All 4 rows.

    i.e. if I click on the first checkbox, row 1, I want the first 4 checkboxes to be ticked. Row 1,2,3 and 4. As they all have the same ColumnP value.

    Field1 ColumnP
    <Checkbox> AAAA
    <Checkbox> AAAA
    <Checkbox> AAAA
    <Checkbox> AAAA
    <Checkbox> BBBB
    <Checkbox> BBBB
    <Checkbox> BBBB
    <Checkbox> BBBB
    <Checkbox> CCCC
    <Checkbox> CCCC
    <Checkbox> CCCC
    <Checkbox> CCCC

    If I tick the last row, then the bottom 4 rows should also tick.
    These 'ticking'/'un-ticking' can happen on any row in Table1.


    Thanks,
    Last edited by Marcster; 02-11-2016 at 09:36 AM. Reason: Added further explanation bellow table.

  4. #4
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    ... and an update query doesn't solve the problem because ...

    Maybe because your checkbox is unbound? But then all checkboxes show the same value so that wont work.

    I don't know.

  5. #5
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Getting the error:
    Run-time error '3601':
    Too few parameters. Expected 1.

    In code:

    Dim CheckBoxValue As Boolean
    Dim ColumnPValue As String
    CheckBoxValue = Forms!Form1!Field1
    ColumnPValue = Forms!Form1!ColumnP
    CurrentDb.Execute "update Table1 set Field1 = " & CheckBoxValue & " where ColumnP = " & ColumnPValue
    Me.Requery

    Any idea's?....

  6. #6
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    That means a field doesn't exist.

    Text fields need quotes around the values.

    for example

    ColumnPValue = "foobar"
    "ColumnP = " & ColumnPValue
    translates to "ColumnP = foobar"

    since foobar doesn't have quotes and isn't numeric it's seen as a field that doesn't exist.

    so if columnp is text it should be

    "ColumnP = '" & ColumnPValue & "'"

  7. #7
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Cheers jonh, that's it.


    CurrentDb.Execute "update Table1 set Field1 = " & CheckBoxValue & " where ColumnP = '" & ColumnPValue & "'"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •