Form Field Properties and how to read them ? 
Author Message
 Form Field Properties and how to read them ?

Hello

I have a Word template for our software specification .
What i want to do amongst all the text is have a table(s) with some :

Text Form Fields
Check Box Fields
Drop-down Form field
(other exist ??)

And bookmark these, e.g.
"Stubs Needed" | [yes/no]
where yes/no is a Check Box Field or Drop-Down Field with a Bookmark

I want to be able to run some VB code to read all these, either sequentially
or looking for
specific bookmarks, then reading what the value is for the object.

In this way we can automate the creation of some skeleton code based on the
spec.

Quote:
>>> For this VB novice , anyone have some code samples to open the current

Word doc
or one with a specific path, and find the bookmarks and object properties
for these type of forms ?
[i can add by own code to use this information]

Most of the Form help i find is using forms to call VB during user input.
I don't want this, i want to read what the user input after the document has
been completed.

Thanks in advance



Tue, 06 Jul 2004 10:02:04 GMT  
 Form Field Properties and how to read them ?
An add on !!

I realise now i also need to tag a table (bookmark?) and be able to read row
entries
for particular column headers ? (this will normally be just text)
The number of rows can vary .

Got a code sample ?

Belows request is for a specific cell .

Thanks and good karma on ya


Quote:
> Hello

> I have a Word template for our software specification .
> What i want to do amongst all the text is have a table(s) with some :

> Text Form Fields
> Check Box Fields
> Drop-down Form field
> (other exist ??)

> And bookmark these, e.g.
> "Stubs Needed" | [yes/no]
> where yes/no is a Check Box Field or Drop-Down Field with a Bookmark

> I want to be able to run some VB code to read all these, either
sequentially
> or looking for
> specific bookmarks, then reading what the value is for the object.

> In this way we can automate the creation of some skeleton code based on
the
> spec.

> >>> For this VB novice , anyone have some code samples to open the current
> Word doc
> or one with a specific path, and find the bookmarks and object properties
> for these type of forms ?
> [i can add by own code to use this information]

> Most of the Form help i find is using forms to call VB during user input.
> I don't want this, i want to read what the user input after the document
has
> been completed.

> Thanks in advance



Tue, 06 Jul 2004 11:20:31 GMT  
 Form Field Properties and how to read them ?
Hi Greg,

Here are a few links and examples to get you going:

First, I think you're talking about formfields and not bookmarks, right?

To set a value to a text formfield, use:
    ActiveDocument.Formfields("NameOfFormfield?).Result = "New Text"
to read a value from either textformfield, checkbox or dropdown:
    Msgbox ActiveDocument.FOrmfields("NameOfFormfield").Result

Note that when you're going to use variables that hold the name of the
formfield, they MUST be declared as Variant and not as String

To set the value for a checkbox formfield, use:
    Activedocument.FormFields("NameOfFormfield").CheckBox.Value = True

If you need to write to bookmarks and you're document is protected, you need
to unprotect it first, write text to the bookmarks    (see
http://www.mvps.org/word/FAQs/MacrosVBA/InsertingTextAtBookmark.htm)
and then reprotect it:

    ActiveDocument.Unprotect
   'Code to write bookmarks '
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True

To open a document:
    Documents.Open(Filename:="Path and Filename.dot")

A bookmarks is an object in a word document, to read them all, use something
like:
Dim oBookmark as Bookmark

    For Each oBookmark in ActiveDocument.Bookmarks
      MsgBox oBookmark.Name & " " & oBookmark.Range.Text
    Next

Code examples to read and write documentproperties
http://www.mvps.org/word/FAQs/MacrosVBA/MixedDocProps.htm

For lots of code examples, visit the Macros/VBA FAQ at www.mvps.org/word

If you need more help once you are started, post back and don't forget to
include the relevant part of the code you're question is about.

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/



Quote:
> Hello

> I have a Word template for our software specification .
> What i want to do amongst all the text is have a table(s) with some :

> Text Form Fields
> Check Box Fields
> Drop-down Form field
> (other exist ??)

> And bookmark these, e.g.
> "Stubs Needed" | [yes/no]
> where yes/no is a Check Box Field or Drop-Down Field with a Bookmark

> I want to be able to run some VB code to read all these, either
sequentially
> or looking for
> specific bookmarks, then reading what the value is for the object.

> In this way we can automate the creation of some skeleton code based on
the
> spec.

> >>> For this VB novice , anyone have some code samples to open the current
> Word doc
> or one with a specific path, and find the bookmarks and object properties
> for these type of forms ?
> [i can add by own code to use this information]

> Most of the Form help i find is using forms to call VB during user input.
> I don't want this, i want to read what the user input after the document
has
> been completed.

> Thanks in advance



Wed, 07 Jul 2004 00:37:27 GMT  
 Form Field Properties and how to read them ?
Many thanks

Quote:

> First, I think you're talking about formfields and not bookmarks, right?

Hmm yes, but the FORM has a field "bookmark" under "field settings" which i
assume is the name of the field.

Had a quick look at
http://www.mvps.org/word/FAQs/MacrosVBA/MixedDocProps.htm
Love the style

Do these pages have info on ... thanks

"I realise now i also need to tag a table (bookmark?) and be able to read
row
entries
for particular column headers ? (this will normally be just text)
The number of rows can vary .

Got a code sample ?

Belows request is for a specific cell ."

Thanks and good karma on ya



Wed, 07 Jul 2004 06:38:40 GMT  
 Form Field Properties and how to read them ?
Hi Greg,

Quote:
> "I realise now i also need to tag a table (bookmark?) and be able to read
> row
> entries
> for particular column headers ? (this will normally be just text)
> The number of rows can vary .

> Got a code sample ?

I'm not exactly sure I understand what you need to do, but here are some
code examples that can be used with tables:

----------------------------------------------
Sub ShowTable()
Dim oTable As Table
Dim oCell As Cell

  Set oTable = ActiveDocument.Tables(1)

  'Loop through all the cells in the table
  For Each oCell In oTable.Range.Cells
    'Strip last two characters
    'to read what's in the cell
    MsgBox Left(oCell.Range.Text, _
                Len(oCell.Range.Text) - 2)
  Next

  'Loop all the cells in first column
  For Each oCell In oTable.Columns(1).Cells
    MsgBox Left(oCell.Range.Text, _
                Len(oCell.Range.Text) - 2)
  Next

  'Loop through all the cells in the first row
  For Each oCell In oTable.Rows(1).Cells
    MsgBox Left(oCell.Range.Text, _
                Len(oCell.Range.Text) - 2)
  Next

  'Check if selection is in a table
  If Selection.Information(wdWithInTable) Then
    MsgBox "in table"
  Else
    MsgBox "not in table"
  End If

  'Get the current columnnumber
  If Selection.Information(wdWithInTable) Then
    MsgBox Selection.Information(wdEndOfRangeColumnNumber)
    'or row number
    MsgBox Selection.Information(wdEndOfRangeRowNumber)
  End If

  Set oCell = Nothing
  Set oTable = Nothing
End Sub
----------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/



Wed, 07 Jul 2004 09:47:14 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Help: I can't read the description property for Table fields using VBA

2. Reading the Custom Properties fields using VBA

3. Are field properties read only?

4. How do I read Target field from Shortcut (*.lnk) properties

5. Reading a field and using that field to place a number in another field

6. Programmatically transfer DecimalPlaces property from table field to form text box

7. set text form field properties within a macro

8. setting form field properties within a macro

9. programmatically create forms / ADO field properties

10. Changing a field to Read only when form sent if it contains data

11. Reading form fields

12. Reading form fields

 

 
Powered by phpBB® Forum Software