I am developing a series of templates for my company for faxes,
letters, quotation requests, call reports, etc. Since all of these
documents need to share a somewhat dynamic list of vendors, I used the
information from Doug Robbins' reply to Mary Henderson's July 2002 post
entitled "Drop down lists" to create a separate table of information
with which to populate my templates. This way I could change the list
and have all the templates reflect the new information.
I have developed the userform and the template. I am using bookmarked
fields in my Word template rather than just bookmarks. Here is the
problem:
Without any breakpoints toggled on in VBA, I get a Run-time error 4198
in my application. However, when I turn on a breakpoint in VBA and
simply resume program execution following the break, the application
runs perfectly.
I have confirmed this problem on a machine running Word 2003 SP1 as
well as a machine running Word 2002 SP3.
Here is my code:
Private Sub Cmdclose_Click()
Unload Me
End Sub
Private Sub ComboBox1_Change()
ActiveDocument.FormFields("PrinName").Result = ComboBox1.Value
End Sub
Private Sub UserForm_Initialize()
Dim sourcedoc As Document, i As Integer, j As Integer, myitem As
Range, m As Long, n As Long
Application.ScreenUpdating = True
' Open the file containing the ISI Principal List
' Modify the path in the following line so that it matches where
you saved ISI Principal List.doc
Set sourcedoc =
Documents.Open(FileName:="C:\Hold\WordTests\Principals.doc")
' Get the number of Principals = number of rows in the table ISI
Principal List
' less one, assuming that the first row is a header row
i = sourcedoc.Tables(1).Rows.Count - 1
' Get the number of columns in the table ISI Principals List
j = sourcedoc.Tables(1).Columns.Count
' Set the number of columns in the Listbox to match
' the number of columns in the table ISI Principals List
ComboBox1.ColumnCount = j
' Define an array to be loaded with the Principal data
Dim MyArray() As Variant
'Load client data into MyArray
ReDim MyArray(i, j)
For n = 0 To j - 1
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(1).Cell(m + 2, n + 1).Range
myitem.End = myitem.End - 1
MyArray(m, n) = myitem.Text
Next m
Next n
' Load data into ComboBox1
ComboBox1.List() = MyArray
' Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub
Amy Blankenship - 20 Sep 2005 17:09 GMT
Where is it erroring?
-Amy
>I am developing a series of templates for my company for faxes,
> letters, quotation requests, call reports, etc. Since all of these
[quoted text clipped - 60 lines]
> sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
> End Sub
Matt - 20 Sep 2005 17:37 GMT
Hi Amy!
That is an interesting question, because it is hard to determine.
When I tab into the field on my Word template it triggers the
gocombobox subroutine contained in Module1. That module is one line of
code: UserForm.Show. Then I see the Principals.doc document open
moments before the error dialog appears.
When I click debug, however, it takes me to the UserForm.Show line in
Module1, even though I know the Initialize event for the UserForm has
at least started.
I hope that helps. Thanks for any assistance you can render!
Amy Blankenship - 20 Sep 2005 17:50 GMT
Where are you putting the break that is preventing the problem from
manifesting?
-Amy
> Hi Amy!
>
[quoted text clipped - 10 lines]
>
> I hope that helps. Thanks for any assistance you can render!
Jean-Guy Marcil - 20 Sep 2005 18:43 GMT
Matt was telling us:
Matt nous racontait que :
> Hi Amy!
>
[quoted text clipped - 8 lines]
> Module1, even though I know the Initialize event for the UserForm has
> at least started.
At that point hit F8 in the VBA editing window to step through the code line
by line until you get to the line that causes the error.

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Matt - 20 Sep 2005 19:21 GMT
Amy:
I can put the breakpoint literally on any line of the code and when I
resume it runs properly.
Jean-Guy:
Actually since Module1's code and the UserForm_Initialize code are in
separate containers, F8 does nothing when I press it after the error
dialog. At that point I am looking at the Module1 line of code.
Thank you both!
Amy Blankenship - 20 Sep 2005 20:08 GMT
What if you put it directly below the loop?
-Amy
> Amy:
>
[quoted text clipped - 8 lines]
>
> Thank you both!
Jean-Guy Marcil - 20 Sep 2005 21:06 GMT
Matt was telling us:
Matt nous racontait que :
> Jean-Guy:
>
> Actually since Module1's code and the UserForm_Initialize code are in
> separate containers, F8 does nothing when I press it after the error
> dialog. At that point I am looking at the Module1 line of code.
Have you tried debugging step by step from the start of the code? When you
get to the part of the code that calls the userform, the debugger should get
into the initialize code and debug line by line. Or, set the cursor in the
Initialize part of the code and Hit F8 to debug the creation of the form.
I do this all the time.
Just to make sure, use something like this:
Dim MyForm as UserForm1 'Or whatever name you have given to the userform
Set MyForm = New UserForm1
Load MyForm
MyForm.Show
....'Other stuff
Unload MyForm
Set MyForm = Nothing
And try debugging.
(Replace the Unload Me for a Me.Hide in the Close button code).

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Matt - 21 Sep 2005 16:25 GMT
I decided to go a different route. This is not an optimal solution,
but it appartently works around the problem I have yet to be able to
find.
Instead of using the fields in Word to call the subroutine that shows
the form, I used the AutoNew macro. This one change resolved the
problem - the rest of the code functions properly.
I suspect that there is some bug in the software that just happens to
plant itself in the middle of what I was attempting to do.
Nevertheless, this will work fine.
Thank you for your assistance! I do appreciate your thoughtful advice.
Matt