Log in

View Full Version : [SOLVED:] Word UserForm with Counter



SteveHale
05-09-2019, 12:34 PM
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! :hi:

-Steve

gmaxey
05-09-2019, 03:33 PM
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

SteveHale
05-10-2019, 01:30 PM
IT WORKS!

Thanks Greg!:bow:

-Steve