Welcome to SPN

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

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

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
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page