Link to home
Start Free TrialLog in
Avatar of daleoran
daleoranFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBA - Count how many textboxes aren't blank

I've created a form in Word and on it I have 8 text boxes for user input. However not all the text boxes will be used all the time so how do I count how many have been used?

Any coding examples would be very much appreciated.

Sorry but 95 points is all I have.
Sorry tag should be Word 2007
Avatar of Xcone
Xcone
Flag of Netherlands image

Can you specify wether you use formfields within a document. Or do you have a form (as in Dialog)?

You can access formfields collection with VBA "ActiveDocument.FormFields"
You can access controls on a form with VBA "<FormName>.Controls"

Just use a For Each loop on those, and perform additional checks if you're dealing with textboxes. Then perform the check if it contains text.

I can give you a code example once you specify the type of editbox you're talking about.
Avatar of daleoran

ASKER

Sorry it's a form (as in dialog) called from a macro using InputForm.Show vbModal
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works a treat Graham but I have worded the question wrong - points are yours but hope you can help just a wee bit more.

What should have said was that I have a group of text boxes on a form which has around 20 text boxes in total. How do I count the unused boxes from the group of 8.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How are they grouped? I don't know what the gropubox that XCone refers to is, but if they are in a Frame, the syntax is the same:

For Each ctrl in Me.Frame1.Controls
I meant Frame, sorry about that. GroupBox and Frame are the same thing. I use them a lot in another environment where it's called a GroupBox.
Hope you don't mind the split with Xcone. He did suggest the code first even if the name was slightly wrong.

Many thanks for all the help.