Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2003
    Posts
    9

    Unanswered: Framegroup using bitvalues and checkboxes

    I am trying to create a framegroup with checkboxes, where each individual checkbox in the framegroup can stay on or off, meaning I want to be able to select (check) several checkboxes, or any combination on or off, not just the limitation of only any one checkbox on, and none other.

    Hmm, maybe not the best description. But I have a field in a table, that is a bit value, see this table field example:

    numAttributes
    0;"";1;"Metal";2;"Heavy";4;"Long"

    Now an entry for the above example could have none, or several of the above attributes. So the stored value for an object that is made of metal, and is heavy and long, would have the value 7 (1+2+4)

    Now I want the same on my form, but creating a framegroup with the wizard, I can only select one checkbox at any given time. I want the option to select none, or any combination of them all, and then have the values for each checkbox stored in the table.

    I am kind of surprised that this has not been thought of by Microsoft.

    For this particular database, I have MANY of such attribute type fields. Any ideas?

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by DKDiveDude
    I am trying to create a framegroup with checkboxes, where each individual checkbox in the framegroup can stay on or off, meaning I want to be able to select (check) several checkboxes, or any combination on or off, not just the limitation of only any one checkbox on, and none other.

    Hmm, maybe not the best description. But I have a field in a table, that is a bit value, see this table field example:

    numAttributes
    0;"";1;"Metal";2;"Heavy";4;"Long"

    Now an entry for the above example could have none, or several of the above attributes. So the stored value for an object that is made of metal, and is heavy and long, would have the value 7 (1+2+4)

    Now I want the same on my form, but creating a framegroup with the wizard, I can only select one checkbox at any given time. I want the option to select none, or any combination of them all, and then have the values for each checkbox stored in the table.

    I am kind of surprised that this has not been thought of by Microsoft.

    For this particular database, I have MANY of such attribute type fields. Any ideas?
    Yeah. Drop the option group and use a rectangle to give you the same visual effect.
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Apr 2003
    Posts
    9
    Yes, I guess I should have mentioned, what to do besides that suggestion

    But I wanted to avoid adding 100+ checkbox manually, and creating Visual Basic behind to add up bit values and store.

    Thanks anyways...

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    I think you need to keep running with M Owen's idea a little longer. Possibly not the most refined solution, but a starting point off the top of my head-
    Create the check boxes individually and enclose in rectangle. Use a naming convention (cck01 for Metal, cck02 Heavy etc). When the button is clicked, loop through the forms controls. If it is a checkbox and value is true, strip off last two charcters, convert to integer, add to running sum. Use this sum for your final value.
    Alternatively, store your checkbox names in an array or table with their associated values and sum these where the corresponding check box is ticked.
    HTH

    BTW - forgot to mention with first post - once you've set something like this up the code is recycleable for any form so it gets easier once you've settled on how you are going to do it
    Last edited by pootle flump; 05-24-04 at 14:03.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Apr 2003
    Posts
    9
    Thanks, and I was actually in the middle of doing it all manually, when you replied.

  6. #6
    Join Date
    Apr 2003
    Posts
    9
    Ok, I came up with the following solution, not award winning, but

    1) To display a number as bits spread over multiple check boxes is easy, just set each checkbox's control source to the following:

    Checkbox 1 =AndBitwiseComparison([numAttribute],1)
    Checkbox 2 =AndBitwiseComparison([numAttribute],2)
    Checkbox 3 =AndBitwiseComparison([numAttribute],4)
    etc.....

    numAttribute is the field where the data is stored off course, and AndBitwiseComparison is a custom function that does a bitwise AND operation since the crappy "Expression Builder" does not support bitwise commands. It takes the parameters current field value and bit comparison value.

    Public Function AndBitwiseComparison(numValue As Long, numComparison As
    Long) As Long
    AndBitwiseComparison = numValue And numComparison
    End Function


    2) Now to actually set the value, after clicking a checkbox was a bit, no phun intended, more tricky as with my limited Access knowledge, I can not set a field value from another fields event using Expression Builder.

    Another strange thing, is that the event Single Click did NOT work, so I used double click. So for each checkbox, I use the following on the "On Dbl Click" event:

    Checkbox 1 =XorBitwiseComparison("Attribute",[numAttribute],1)
    Checkbox 2 =XorBitwiseComparison("Attribute",[numAttribute],2)
    Checkbox 3 =XorBitwiseComparison("Attribute",[numAttribute],8)
    etc.....

    Where XorBitwiseComparison is a custom function, that takes as parameters my checkbox group name, current value, and Xor bitvalue), like this:

    Public Function XorBitwiseComparison(txtField As String, numValue As
    Long, numComparison As Long) As Long
    Select Case txtField
    Case "Attribute1": Forms!frmTest!numAttribute = numValue
    Xor numComparison
    Case "Attribute2": Forms!frmTest!numAttribute = numValue
    Xor numComparison
    Case "Attribute3": Forms!frmTest!numAttribute = numValue
    Xor numComparison
    etc......
    End Select
    End Function


    Any ideas on how to make this smoother?
    Last edited by DKDiveDude; 05-24-04 at 16:05.

Posting Permissions

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