Reading form fields 
Author Message
 Reading form fields

Hi,

I have written some VBA which loops through all the form
fields in a Word document, and assigns all their values to
an array. This loop is started when the user clicks a
Submit button on the document.

I would like to display a message box which tells the user
to 'please wait' whilst the loop is running (it is a long
form!). However, my problem is that when the loop is
running, the screen flickers as it scrolls through the
document.

Is there anyway to stop the document visibly scrolling /
screen flickering, whilst it's form fields are being read?

Many thanks for any help,
Martin



Sun, 01 Aug 2004 20:20:32 GMT  
 Reading form fields
Hi, Martin,

The fact that your screen flickers indicates that your macro is moving the Selection object from
field to field. Don't do that!

You can fill the array by addressing the form fields directly, without moving the Selection at all
and without scrolling the screen. Do something like this:

    Dim strArray(50) As String
    Dim index As Integer

    With ActiveDocument
        For index = 1 To .FormFields.Count
            strArray(index) = .FormFields(index).Result
        Next index
    End With

As a bonus, it will run *much* faster -- the whole loop probably won't take more than a second.

You will need to set the size of the array (where I used 50) to be equal to or slightly larger than
the number of fields in the document, or else you'll get an error when the loop index exceeds the
size. If the number of fields in the template changes frequently, you'll need to look into the ReDim
statement for adjusting the array size.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Hi,

> I have written some VBA which loops through all the form
> fields in a Word document, and assigns all their values to
> an array. This loop is started when the user clicks a
> Submit button on the document.

> I would like to display a message box which tells the user
> to 'please wait' whilst the loop is running (it is a long
> form!). However, my problem is that when the loop is
> running, the screen flickers as it scrolls through the
> document.

> Is there anyway to stop the document visibly scrolling /
> screen flickering, whilst it's form fields are being read?

> Many thanks for any help,
> Martin



Sun, 01 Aug 2004 22:24:53 GMT  
 Reading form fields
Hi Jay,

Thanks for the reply.

I am using code similar to yours, except that instead of
assigning each form field value to an array, I am creating
an XML string (as below):

sXML = "<form>"

    With ActiveDocument

        sXML = "<field name=""fldName"" value="""
& .FormFields("Text1").Result & """/>"
        sXML = sXML & "<field name=""fldBand"" value="""
& .FormFields("Text2").Result & """/>"
        sXML = sXML & "<field name=""fldStaffNo""
value=""" & .FormFields("Text3").Result & """/>"
        sXML = sXML & "<field name=""fldDept"" value="""
& .FormFields("Text4").Result & """/>"
        sXML = sXML & "<field name=""fldDivison""
value=""" & .FormFields("Text5").Result & """/>"
        sXML = sXML & "<field name=""fldFrom"" value="""
& .FormFields("Text6").Result & """/>"
        sXML = sXML & "<field name=""fldTo"" value="""
& .FormFields("Text7").Result & """/>"
        sXML = sXML & "<field name=""fldMidYear""
value=""" & .FormFields("Text8").Result & """/>"
        sXML = sXML & "<field name=""fldRO"" value="""
& .FormFields("Text9").Result & """/>"
        sXML = sXML & "<field name=""fldCO"" value="""
& .FormFields("Text9").Result & """/>"

    End With

    createXMLString = sXML & "</form>"

This code is contained in a module inside my Word doc, and
is called by the click sub for an ActiveX button.

I have just found the 'ScreenUpdating' property which has
removed the flicker- however a 'please wait' userform that
I try to display is still remaining blurred whilst the
form fields are being read.

It is most puzzling!

Thanks again for your help,
Martin

Quote:
>-----Original Message-----
>Hi, Martin,

>The fact that your screen flickers indicates that your

macro is moving the Selection object from
Quote:
>field to field. Don't do that!

>You can fill the array by addressing the form fields

directly, without moving the Selection at all
Quote:
>and without scrolling the screen. Do something like this:

>    Dim strArray(50) As String
>    Dim index As Integer

>    With ActiveDocument
>        For index = 1 To .FormFields.Count
>            strArray(index) = .FormFields(index).Result
>        Next index
>    End With

>As a bonus, it will run *much* faster -- the whole loop

probably won't take more than a second.
Quote:

>You will need to set the size of the array (where I used

50) to be equal to or slightly larger than
Quote:
>the number of fields in the document, or else you'll get

an error when the loop index exceeds the
Quote:
>size. If the number of fields in the template changes

frequently, you'll need to look into the ReDim
Quote:
>statement for adjusting the array size.

>--
>Regards,
>Jay Freedman
>Microsoft Word MVP        Word MVP FAQ site:

http://www.mvps.org/word
Quote:



>> Hi,

>> I have written some VBA which loops through all the form
>> fields in a Word document, and assigns all their values
to
>> an array. This loop is started when the user clicks a
>> Submit button on the document.

>> I would like to display a message box which tells the
user
>> to 'please wait' whilst the loop is running (it is a
long
>> form!). However, my problem is that when the loop is
>> running, the screen flickers as it scrolls through the
>> document.

>> Is there anyway to stop the document visibly scrolling /
>> screen flickering, whilst it's form fields are being
read?

>> Many thanks for any help,
>> Martin

>.



Sun, 01 Aug 2004 23:32:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Reading form fields

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

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

4. Form Field Properties and how to read them ?

5. VBA reading a field form a query in Access

6. Need help reading Outlook keyword fields into Access field

7. Read HTML formatted data from database field, Insert Wordmerge fields, and save as Word document

8. Populate form fields from email Fields

9. Help!!! From form field to Word field

10. on entry form text field macro - year field

11. Problem when unprotecting a document with form field text fields

12. Starting query from a form (criterium being based on a text field in the form)

 

 
Powered by phpBB® Forum Software