Count unbonded text control that are not null

S

Silvio

How do I programmatically count how many control in my form are not null?
All the controls are unbounded. The form has 13 controls. This total will
progress as the user fills in all the required control. In short, I have a
progress bar (13 means 100%) that will count the progress until all the
controls are totally filled and ready to be saved.
 
M

Marshall Barton

Silvio said:
How do I programmatically count how many control in my form are not null?
All the controls are unbounded. The form has 13 controls. This total will
progress as the user fills in all the required control. In short, I have a
progress bar (13 means 100%) that will count the progress until all the
controls are totally filled and ready to be saved.


Because there may be many other controls on the form, I
suggest that you use the Tag property (set to DATA) to
identify the ones that you want to check. The code could
then be:

Dim ctl As Control
Dim CtlCnt As Integer, CtlFilled As Integer
For Each ctl In Me.Controls
If ctl.Tag = "DATA" Then
CtlCnt = CtlCnt + 1
If Not IsNull(ctl) Then
CtlFilled = CtlFilled + 1
End If
End If
Next ctl
 
S

Silvio

Marshall, I found the TAG property, however I am getting 0 count despite
having data in some of the fields. It appear like the DATA tag is not
detected and the code lookps through all the controld without making anything
count.
 
M

Marshall Barton

No. Each control has a Tag property that you can use for
whatever purpose you want.
 
S

Silvio

I got it! Thank you a million. To help other this is "my" working code:

Private Sub txtCurrent_LostFocus()

Dim ctl As Control
Dim CtlCnt As Integer, CtlFilled As Integer
For Each ctl In Me.Controls
If ctl.Tag = "DATA" Then
CtlCnt = CtlCnt + 1
If Not IsNull(ctl) Then
CtlFilled = CtlFilled + 1
End If
End If
Next ctl
Me.txtCurrent = CtlFilled

End Sub
 
S

Silvio

Marshall, I have one more question for you if you don't mind. How can I make
this function available to all the fields in my form so I don't have to enter
the same code over and over again for each control in my form using on
Lost_Focus? Please be specific.

Thanks again!!!


Thanks again!!!

Marshall Barton said:
No. Each control has a Tag property that you can use for
whatever purpose you want.
--
Marsh
MVP [MS Access]

Thanks, Marshall. Are you referring to Smart Tag when you say Tag?
 
M

Marshall Barton

Don't put the code in an event procedure. Instead, put it
in a separate Public function in the form's module.

Public Function CountFilled()
Dim ctl As Control
. . .
End Function

Then, change the OnLostFocus event **property** from
[Event Procedure]
to
=CountFilled()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top