How to validate WORD 2007 forms using VBA

Y

YesHoney

I have created a WORD 2007 form (without using legacy tools). How to
validate input?
 
J

Jay Freedman

YesHoney said:
I have created a WORD 2007 form (without using legacy tools). How to
validate input?

That's nowhere near enough information.

If you didn't use legacy tools, what did you use?

What rules should be followed to validate the input? What is the input
supposed to be? Where is it? Do any of the inputs depend on other inputs?
What do you want to do if any input is not valid?

There are probably quite a few other questions to answer as the design
becomes more detailed, but those are the minimum.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Y

YesHoney

My problem is I dont know how to refer to data typed by user. Say the WORD
2007 form (not a userform created via VBA) requests AGE and I want to
validate age is in certain range. My problem is how to pass the TYPED age to
VBA. Using legacy tools it's simple. But I'd like to do it without the
legacy tools.
Thx for payin attention to my request.
 
J

Jay Freedman

Is the information just typed somewhere in the regular text of the document?
Or is it in a bookmark, or in a table cell, or in a content control, or some
other place that's recognizable?
 
Y

YesHoney

In a textbox.


Jay Freedman said:
Is the information just typed somewhere in the regular text of the document?
Or is it in a bookmark, or in a table cell, or in a content control, or some
other place that's recognizable?
 
J

Jay Freedman

That's a problem -- actually, several problems.

The first problem is that text boxes (and here I'm assuming you mean one from
the Insert > Text Box button) don't typically have names or associated bookmarks
like legacy form fields, and they don't have any way to automatically run a
macro.

If the form is created as a template and the users make new documents from the
template, your macro *may* be able to assume that the text box for a specific
piece of data always has the same index in the document, for example,
ActiveDocument.Shapes(1) or ActiveDocument.Shapes(5) or whatever. If the users
can edit the document, though, sooner or later somebody will delete a text box
or other shape and all the indexes after that will change.

However, you *can* assign a name to a text box in the template, for example by
running a line like this one time during your development phase:

ActiveDocument.Shapes(5).Name = "AgeBox"

and the macro can then get the text from it like this, which will be the same
regardless of whether the index number changes:

ActiveDocument.Shapes("AgeBox").TextFrame.TextRange.Text

I'll leave the problem of how to run the code to you for now. Come back if you
need help with that.
 
Y

YesHoney

Thx. Will switch to legacy form fields.



Jay Freedman said:
That's a problem -- actually, several problems.

The first problem is that text boxes (and here I'm assuming you mean one from
the Insert > Text Box button) don't typically have names or associated bookmarks
like legacy form fields, and they don't have any way to automatically run a
macro.

If the form is created as a template and the users make new documents from the
template, your macro *may* be able to assume that the text box for a specific
piece of data always has the same index in the document, for example,
ActiveDocument.Shapes(1) or ActiveDocument.Shapes(5) or whatever. If the users
can edit the document, though, sooner or later somebody will delete a text box
or other shape and all the indexes after that will change.

However, you *can* assign a name to a text box in the template, for example by
running a line like this one time during your development phase:

ActiveDocument.Shapes(5).Name = "AgeBox"

and the macro can then get the text from it like this, which will be the same
regardless of whether the index number changes:

ActiveDocument.Shapes("AgeBox").TextFrame.TextRange.Text

I'll leave the problem of how to run the code to you for now. Come back if you
need help with that.
 

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