Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Enumerating through controls to extract values using tag property

Discussion in 'Information Technology' started by tcb, Nov 3, 2005.

  1. tcb

    tcb
    Expand Collapse
    Guest

    I want to add up the values of several textboxes on a form using the
    tag property. In this case, tag = "grade"

    Is this possible? I know you can set properties of controls but can
    you extract the values of those controls also?
     
  2. Loading...


  3. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    Dim ctlCurr As Control
    Dim lngTotal As Long

    For Each ctlCurr In Me.Controls
    If ctlCurr.Tag = "grade" Then
    lngTotal = lngTotal + ctlCurr
    End If
    Next ctlCurr


    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "tcb" <tbenson@mn.rr.com> wrote in message
    news:1130955102.099405.95800@g44g2000cwa.googlegroups.com...
    > I want to add up the values of several textboxes on a form using the
    > tag property. In this case, tag = "grade"
    >
    > Is this possible? I know you can set properties of controls but can
    > you extract the values of those controls also?
    >
     
  4. tcb

    tcb
    Expand Collapse
    Guest

    Thanks, I like that better than my solution. Before your message was
    posted I tried something similar but my code was failing due to null
    values in the text boxes (took me a while to figure that out).
    Meanwhile I tried something a bit different which took more typing than
    yours.

    Dim frmCurrentForm As Form
    Set frmCurrentForm = Screen.ActiveForm

    Dim ctl As Control
    Dim strFieldName As String
    Dim intAgeGroupValue As Long
    Dim intTotalAgeGroupValue As Long

    For Each ctl In frmCurrentForm.Controls

    If ctl.Tag = "AgeGroup" Then

    strFieldName = ctl.ControlSource
    intAgeGroupValue = NTZ(frmCurrentForm.Recordset.Fields(strFieldName))
    intTotalAgeGroupValue = intTotalAgeGroupValue + intAgeGroupValue

    End If

    Next ctl

    If intTotalAgeGroupValue <> Me.TotalInds Then

    MsgBox ("Total by Grade Does Not Match Total Individuals"), ,
    "Totals Do Not Match"

    End If
     

Share This Page