R
Rinze Smit
Hello,
I'm trying to build a template with some formfield-elements.
I need a combobox with more than 25 items, so I use the formfield-
workaround.
I have a formfield which calls a macro "NaarCombo"
-------------------------------
Sub NaarCombo()
Load frmCombo
frmCombo.Show
Application.ScreenUpdating = True
Documents("organisatieonderdelen").Close
'SaveChanges:=wdDoNotSaveChanges
End Sub
-------------------------------
Then in the initialize I fill the combobox. This part works fine.
However, when I try to close the sourcedocument, I get error 4198.
I think this error occurs because the file is still somehow in use.
But I can't see why.
I've tried to change the location of the code for closing the
document. fx: I placed it in sub "NaarCombo". However, this didn't
work. I still got the same error.
I've also tried copying it to "document_close"
This works, but if there are no other documents open, it also closes
Word....
Another option would be to use an Exceldocument as source, but I think
that will be 'slower'.
Can anyone give me some tips in this?
The code in Userform_intialize::::
----------------------------------------
Private Sub UserForm_Initialize()
cmbOrgOnd.ColumnCount = 1
'Load data into ComboBox
' Deze makro laadt de gegevens uit het bestand
organisatieonderdelen.doc in een keuzelijst van het document.
Dim i As Integer, j As Integer, myitem As Range, m As Long, n As Long
'dan de gegevens vanuit de array in de dropdownbox laden.
'dropdownbox moet altijd de naam "OrgOnd" hebben.
strTargetname = ActiveDocument.Name
Application.ScreenUpdating = False
' Open het bestand met de organisatieonderdelen
Set sourcedoc = Documents.Open(FileName:="G:\SjablonenStart-Dir
\databases\organisatieonderdelen.doc")
' Het aantal rijen ophalen
i = sourcedoc.Tables(1).Rows.Count
' Definieer de array waar de organisatieonderdelen in worden
opgeslagen
Dim MyArray() As Variant
'Laad gegevens uit de tabel in de Array
ReDim MyArray(i)
For n = 1 To i + 1
Set myitem = sourcedoc.Tables(1).Cell(n, 1).Range
myitem.End = myitem.End - 1
MyArray(n - 1) = myitem.Text
Next n
' Sluit het bestand met de organisatieonderdelen
cmbOrgOnd.List() = MyArray()
'I've tried to use several other codefragments before the real
'close-statement'. Nothing worked.
'sourcedoc.Saved = True
'Documents("G:\SjablonenStart-Dir\databases
\organisatieonderdelen.doc (Alleen-lezen)").Close
'sourcedoc.Activate
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
Documents(strTargetname).Activate
End Sub
--------------------------------
Many thanks in advance
Rinze Smit
Revalidatie Friesland
I'm trying to build a template with some formfield-elements.
I need a combobox with more than 25 items, so I use the formfield-
workaround.
I have a formfield which calls a macro "NaarCombo"
-------------------------------
Sub NaarCombo()
Load frmCombo
frmCombo.Show
Application.ScreenUpdating = True
Documents("organisatieonderdelen").Close
'SaveChanges:=wdDoNotSaveChanges
End Sub
-------------------------------
Then in the initialize I fill the combobox. This part works fine.
However, when I try to close the sourcedocument, I get error 4198.
I think this error occurs because the file is still somehow in use.
But I can't see why.
I've tried to change the location of the code for closing the
document. fx: I placed it in sub "NaarCombo". However, this didn't
work. I still got the same error.
I've also tried copying it to "document_close"
This works, but if there are no other documents open, it also closes
Word....
Another option would be to use an Exceldocument as source, but I think
that will be 'slower'.
Can anyone give me some tips in this?
The code in Userform_intialize::::
----------------------------------------
Private Sub UserForm_Initialize()
cmbOrgOnd.ColumnCount = 1
'Load data into ComboBox
' Deze makro laadt de gegevens uit het bestand
organisatieonderdelen.doc in een keuzelijst van het document.
Dim i As Integer, j As Integer, myitem As Range, m As Long, n As Long
'dan de gegevens vanuit de array in de dropdownbox laden.
'dropdownbox moet altijd de naam "OrgOnd" hebben.
strTargetname = ActiveDocument.Name
Application.ScreenUpdating = False
' Open het bestand met de organisatieonderdelen
Set sourcedoc = Documents.Open(FileName:="G:\SjablonenStart-Dir
\databases\organisatieonderdelen.doc")
' Het aantal rijen ophalen
i = sourcedoc.Tables(1).Rows.Count
' Definieer de array waar de organisatieonderdelen in worden
opgeslagen
Dim MyArray() As Variant
'Laad gegevens uit de tabel in de Array
ReDim MyArray(i)
For n = 1 To i + 1
Set myitem = sourcedoc.Tables(1).Cell(n, 1).Range
myitem.End = myitem.End - 1
MyArray(n - 1) = myitem.Text
Next n
' Sluit het bestand met de organisatieonderdelen
cmbOrgOnd.List() = MyArray()
'I've tried to use several other codefragments before the real
'close-statement'. Nothing worked.
'sourcedoc.Saved = True
'Documents("G:\SjablonenStart-Dir\databases
\organisatieonderdelen.doc (Alleen-lezen)").Close
'sourcedoc.Activate
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
Documents(strTargetname).Activate
End Sub
--------------------------------
Many thanks in advance
Rinze Smit
Revalidatie Friesland