List box, multiselect

  • Thread starter Thread starter Tammy
  • Start date Start date
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
 
Tammy,
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)

I don't know if this is the solution to your problem, but naming a
user defined variable (or objects etc.) 'Name' is asking for big
trouble. Name is a property name for lots of Access/DAO/ADO objects,
there is even a Name statement. So please change this.

To find the error you should set a breakpoint (or a MsgBox) on (or
before) the GetObject statement and take a good look to strPath.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Well, here's the latest. I am recieving an error "object
does not support that property" on the bookmark line. It
appears not to recognize the bookmark, and this time it
does exist. I have referred to earlier code where I use
the same concept, but there I have the object set
to "word.application" and it works fine, but there I am
opening a completely new doc (through a template). Here,
I am opening an existing doc (created using the
template); and I have an object variable set to that
particular doc which needs opened - how do I fix this??

THANKS!
 
Back
Top