T
Tammy
Following I have some code which is to work with a
listbox. The user selects document titles which are to
be updated (using automation, in the background). The
code seems to work, until it tries to open the doc where
I am getting a "mismatch" error (I have designated the
line w/an **). I am passing the name of the document;
don't know if the error might have something to do with
the index or not - would appear to me that this is
working correctly - the "name" variable shows the
expected data (name of doc user highlighted). This same
line of code works in another sub using a string data
type.
Hopefully I have explained this clearly - please let me
know if you have any ideas!
Private Sub cmdRelate_Click()
Dim ctlList As Control
Dim varItem As Variant
Dim strNewRelated As String
Dim varSelItem As Variant
strNewRelated = Me![SOP Name]
Set ctlList = Forms![NewSOP]![lstSOPs]
'runs through selected items, calls procedure to
'edit existing SOPs & print list of related
For Each varSelItem In ctlList.ItemsSelected
varItem = ctlList.ItemData(varSelItem)
Call SOPWork.EditRelated(varItem, strNewRelated)
Debug.Print ctlList.ItemDatea(varSelItem)
Next
Me![lstSOPs].Visible = False
End Sub
Function EditRelated(Name, Related)
'this function finds the selected SOP and updates the
related SOP section
'it does not make the application visible
Dim oApp As Word.Application
Dim strPath As String
strPath = "C:\SavedSOPs\" & Name & ".doc"
**Set oApp = GetObject(strPath)
With oApp
.Selection.GoTo wdGoToBookmark, Name:="Related"
.Selection.Text = Related
End With
oApp.Quit
Set oApp = Nothing
End Function
listbox. The user selects document titles which are to
be updated (using automation, in the background). The
code seems to work, until it tries to open the doc where
I am getting a "mismatch" error (I have designated the
line w/an **). I am passing the name of the document;
don't know if the error might have something to do with
the index or not - would appear to me that this is
working correctly - the "name" variable shows the
expected data (name of doc user highlighted). This same
line of code works in another sub using a string data
type.
Hopefully I have explained this clearly - please let me
know if you have any ideas!
Private Sub cmdRelate_Click()
Dim ctlList As Control
Dim varItem As Variant
Dim strNewRelated As String
Dim varSelItem As Variant
strNewRelated = Me![SOP Name]
Set ctlList = Forms![NewSOP]![lstSOPs]
'runs through selected items, calls procedure to
'edit existing SOPs & print list of related
For Each varSelItem In ctlList.ItemsSelected
varItem = ctlList.ItemData(varSelItem)
Call SOPWork.EditRelated(varItem, strNewRelated)
Debug.Print ctlList.ItemDatea(varSelItem)
Next
Me![lstSOPs].Visible = False
End Sub
Function EditRelated(Name, Related)
'this function finds the selected SOP and updates the
related SOP section
'it does not make the application visible
Dim oApp As Word.Application
Dim strPath As String
strPath = "C:\SavedSOPs\" & Name & ".doc"
**Set oApp = GetObject(strPath)
With oApp
.Selection.GoTo wdGoToBookmark, Name:="Related"
.Selection.Text = Related
End With
oApp.Quit
Set oApp = Nothing
End Function