Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

ScreenUpdate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BethB - 07 Oct 2005 16:22 GMT
I have a word template which updates fields from a random access file
combined with a access database using bookmarks.
For some reason the template is showing all the field updates, so I have
tried to set the application.screenupdate to false, but the screen jumps all
over the place apparently adding lines to a table (an end user would think
that it is broken). But it is unacceptable to have the screenupdate set to
true - the user would not want to watch each field populate (there are over
1200 fields).

Any help is appreciated.
Jonathan West - 07 Oct 2005 18:33 GMT
Show us the code that does the field updates - there may be a different way
to approach this

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

>I have a word template which updates fields from a random access file
> combined with a access database using bookmarks.
[quoted text clipped - 8 lines]
>
> Any help is appreciated.
BethB - 07 Oct 2005 19:23 GMT
Option Explicit
Option Base 1

Private Sub Document_New()

Dim InputFilePathIn As String               'Input file from ICIS
Dim ErrorFilePathOut As String              'Output error log containing all
fields not processed
Dim fileinputchar As String                 'Holds full input line before
field split
Dim InputFieldName As String                'After Split - ICIS field name
Dim InputValue As String                    'After Split - ICIS field value
Dim DocBookmark As String                   'Word Bookmark - will contain
InputValue
Dim DocLabel As String                      'Word Field Label - will contain
labels retrieved from DB
Dim x As Integer                            'Character Count for
fileinputchar processing
Dim db As Database                          'Database
Dim rs As Recordset
Dim errorlogopen As String                  'Used to check if the error log
is open
Dim ErrorLogtext As String                  'Error log text
Dim CompareCollection As New Collection     'Holds InputFieldName and
InputValue for comparison
Dim ProcessedData() As Variant
Dim CollectionValue As String
Dim CollectionFieldName As String
Dim Count As Integer

InputFilePathIn = "C:\Documents and Settings\ABC\Desktop\summarytest.txt"
ErrorFilePathOut = "C:\Documents and Settings\ABC\Desktop\summaryerror.txt"
errorlogopen = "no"
Set db = OpenDatabase("C:\Documents and
Settings\lid0rb8\Desktop\benefitsummaryfieldcodes")
           Set rs = db.OpenRecordset("Fieldcodes", dbOpenTable)
           With rs
           .Index = "FieldName"
     

'Clear Values from database
rs.MoveFirst
Do Until rs.EOF

   .Edit
   .Fields("DisplayValue").Value = " "
   .Update

rs.MoveNext
Loop

Open InputFilePathIn For Input As #1

Do While Not EOF(1)

   Line Input #1, fileinputchar
   fileinputchar = LTrim(fileinputchar)
   'Cycle thru the line to search for terminating character and then split
the line into
   'the field name and the value to update.  This calls a function
RemoveLeadingYes because
   'the summaries only contain the Yes if no other text is present.
   If Mid(fileinputchar, 1, 1) = "s" Then
   
   Else
   
       If Mid(fileinputchar, 2, 4) = "ICIS" Then
     

       ActiveDocument.FormFields("ICISPRODID").Result = fileinputchar
       Else
           For x = 1 To Len(fileinputchar)
               If Mid(fileinputchar, x, 1) = "~" Then
               InputFieldName = Left(fileinputchar, x)
               InputValue = RemoveLeadingYes(Right(fileinputchar,
Len(fileinputchar) - (x + 1)))
               End If
       
           Next x
           If Mid(InputFieldName, 1, 1) = "X" Then
           
           Else
               rs.MoveFirst
               rs.Seek "=", InputFieldName
               If rs.NoMatch Then
             
                   If errorlogopen = "no" Then
                       errorlogopen = "yes"
                       Open ErrorFilePathOut For Output As #2
                       ErrorLogtext = "File - " & InputFilePathIn
                       Write #2, ErrorLogtext
                   End If
                   ErrorLogtext = "Field - " & InputFieldName & ", " &
InputValue
                   Write #2, ErrorLogtext
               Else
                   If rs.Fields("Bookmark") = "NA" Then
                   
                   Else
                       InputValue = Left(InputValue, 255)
                       .Edit
                       .Fields("DisplayValue").Value = InputValue
                       .Update
                       
                       Count = Count + 1
                       ReDim Preserve ProcessedData(4, Count)
                       ProcessedData(1, Count) = rs.Fields("Bookmark")
                       ProcessedData(2, Count) = InputValue
                       ProcessedData(3, Count) =
rs.Fields("CompareFieldName")
                       ProcessedData(4, Count) = rs.Fields("Label")
                       'MsgBox ProcessedData(1, Count) & ProcessedData(2,
Count) & ProcessedData(3, Count) & ProcessedData(4, Count)
                   End If
               End If
   
           End If
       End If
   End If
Loop

Close #1
   
   For x = 1 To Count

                   DocBookmark = ProcessedData(1, x)
                   DocLabel = ProcessedData(4, x) & " - "
                   ActiveDocument.FormFields(DocBookmark).Result = DocLabel
                   ActiveDocument.Bookmarks(DocBookmark).Select
                   Selection.InsertAfter ProcessedData(2, x)

  Next x

ActiveDocument.Activate
End With
End Sub

> Show us the code that does the field updates - there may be a different way
> to approach this
[quoted text clipped - 11 lines]
> >
> > Any help is appreciated.
Jonathan West - 10 Oct 2005 13:05 GMT
Hi beth

This is the bit of the code that is the problem.

   For x = 1 To Count

                   DocBookmark = ProcessedData(1, x)
                   DocLabel = ProcessedData(4, x) & " - "
                   ActiveDocument.FormFields(DocBookmark).Result = DocLabel
                   ActiveDocument.Bookmarks(DocBookmark).Select
                   Selection.InsertAfter ProcessedData(2, x)

  Next x

Every time you change the position of the Selection by using the Select
method, the window view jumps to that point. It is slow and looks
unprofessional. For the most part, you should avoid moving the Selection if
you can avoid it. You can change your code so that it is like this

   For x = 1 To Count

                   DocBookmark = ProcessedData(1, x)
                   DocLabel = ProcessedData(4, x) & " - "
                   ActiveDocument.FormFields(DocBookmark).Result = DocLabel
                   ActiveDocument.Bookmarks(DocBookmark).Range.InsertAfter
ProcessedData(2, x)

  Next x

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Option Explicit
> Option Base 1
[quoted text clipped - 157 lines]
>> >
>> > Any help is appreciated.
BethB - 07 Oct 2005 19:28 GMT
FYI - The array processing was added because I have to go back and do come
comparison between different records before determining if someting should
print or if the bookmark should be deleted. The code has not been written yet.

> I have a word template which updates fields from a random access file
> combined with a access database using bookmarks.
[quoted text clipped - 6 lines]
>
> Any help is appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.