Consulting

Results 1 to 3 of 3

Thread: Word UserForm with Counter

  1. #1

    Word UserForm with Counter

    Hello.

    I'm trying to add in a counter within my userform but the results does not seem to appear within the placeholders i have.

    What this should be doing is, it calculates the age of the person, then count how many within that age group appears.

    Here's the code for one of the fields...

    Private Sub frmP1DOB_AfterUpdate()
    Dim frmAge0to5 As Long
    Dim frmAge6to12 As Long
    Dim frmAge13to17 As Long
    
    
    frmP1Age = DateDiff("y", frmP1DOB, Date) / 365
    frmP1Age = Format(frmP1Age, "0")
        
        If frmP1Age <= 5 Then
        frmAge0to5 = frmAge0to5 + 1
        Else
        
         If frmP1Age >= 6 And frmP1Age <= 12 Then
            frmAge6to12 = frmAge6to12 + 1
            Else
    
    
                If frmP1Age >= 13 And frmP1Age <= 17 Then
                frmAge13to17 = frmAge13to17 + 1
                Else
    
    
                End If
            End If
        End If
    End Sub
    Any help would be wonderful and thanks for taking the time to look at this!

    -Steve
    Attached Files Attached Files

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Steve,

    You have declared variables with the same name as controls in the form.

    Private Sub frmP1DOB_AfterUpdate()
      frmP1Age = DateDiff("y", frmP1DOB, Date) / 365
      frmP1Age = Format(frmP1Age, "0")
      If frmP1Age <= 5 Then
        frmAge0to5.Text = Val(frmAge0to5.Text) + 1
      Else
        If frmP1Age >= 6 And frmP1Age <= 12 Then
          frmAge6to12.Text = Val(frmAge6to12.Text) + 1
        Else
         If frmP1Age >= 13 And frmP1Age <= 17 Then
           frmAge13to17.Text = Val(frmAge13to17.Text) + 1
         End If
        End If
      End If
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    IT WORKS!

    Thanks Greg!

    -Steve

Posting Permissions

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