ScreenUpdate

B

BethB

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.
 
B

BethB

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
 
B

BethB

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.
 
J

Jonathan West

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


--
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
 

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