How to use option group (checkbox) to change calculation in textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    How to use option group (checkbox) to change calculation in textbox

    I have an option group with 2 checkboxes :
    MtbAge - option value = 1
    RoadAge - option value = 2

    The textbox where to display MtbAge/RoadAge is called = currentage

    if you select MtbAge it must use
    Code:
    =Format(DateSerial(Year(Date()),12,31)-[Birthdate],'yy')
    to calculate

    if you select RoadAge it must use
    Code:
    =DateDiff("yyyy",[Birthdate],Now())+Int(Format(Now(),"mmdd")<Format([Birthdate],"mmdd"))
    to calculate

    Anybody out there that has an idea how to do this please? See attached screen pic

    ** Edit **
    [imgnothumb]http://bytes.com/attachments/attachment/4513d1294394815/checkbox1.jpg[/imgnothumb]
    Attached Files
    Last edited by NeoPa; Jan 8 '11, 03:22 PM. Reason: To show the pic
  • Andrew Hulting
    New Member
    • Dec 2010
    • 13

    #2
    I would try. I havent tested it, but

    Code:
    chkBox1 = MtbAge - option value = 1
    chkBox2 = RoadAge - option value = 2
    
     If Forms![Main]![chkBox1] = true then textbox=Format(DateSerial(Year(Date()),12,31)-[Birthdate],"yy") 
    If Forms![Main]![chkBox2]= true textbox=DateDiff("yyyy",[Birthdate],Now())+Int(Format(Now(),"mmdd")<Format([Birthdate],"mmdd"))

    Comment

    • neelsfer
      Contributor
      • Oct 2010
      • 547

      #3
      I tried the above, but could not get it to work.
      i am attaching the file. Open race entries.
      As you click on mtb age or road age, it must change the current age textbox in yellow. i also added the 2 formulas to the form to be used.
      thx
      Attached Files

      Comment

      • Andrew Hulting
        New Member
        • Dec 2010
        • 13

        #4
        The -1 is whatever the value is when it is checked, I am working on an extreamly gimped PC right now, as I am havign major issues with dll's being courupt, and not being able to runa any code.

        The premis is that when the condition of the checkbox being selected, than the age text box will use the appropriate formula.

        Code:
        If Forms![CyclistF]![MtbAge] = -1 Then Forms![CyclistF]![currentage] = Format(DateSerial(Year(Date), 12, 31) - [BirthDate], "yy")
        
        If Forms![CyclistF]![RoadAge] = -1 Then Forms![CyclistF]![currentage] = DateDiff("yyyy", [BirthDate], Now()) + Int(Format(Now(), "mmdd") < Format([BirthDate], "mmdd"))

        Comment

        • neelsfer
          Contributor
          • Oct 2010
          • 547

          #5
          thx Andrew
          I got it working through your help. Acalc is the overall name off the option group. I changed the values it produce, to 1 and 2
          Code:
          Private Sub Acalc_Click()
            If Forms![CyclistF]![Acalc] = 1 Then Forms![CyclistF]![currentage] = Format(DateSerial(Year(Date), 12, 31) - [BirthDate], "yy")
             
              If Forms![CyclistF]![Acalc] = 2 Then Forms![CyclistF]![currentage] = DateDiff("yyyy", [BirthDate], Now()) + Int(Format(Now(), "mmdd") < Format([BirthDate], "mmdd"))
          End Sub

          Comment

          Working...