Automation w/Word

T

Tammy

Okay, I have several questions. One, I am trying to take
info from Access to a Word document & insert it at a
bookmark - and at a later time, use the text at that
bookmark. However, the following errors occur.

I am having problems calling this particular procedure
which, depending on when it is called, will have a
different number of arguments. I am having problems with
passing only a couple - even though they are
stated "optional". And I am getting the error "type
mismatch" on the line "BMRange.Text = strText" any
suggestions?

Here is the code:

Call SOPWork.OpenWord(strName,,dtDate,strRev,)
'***#arguments getting "expression" error**

Function OpenWord(strDocName As String, Optional Author
As String, Optional dtDate As Date, Optional Revision As
String, Optional Path As String, Optional Temp As String)
On Error GoTo Err_Edit:

Dim oApp As Object
Dim oDoc As Object

Set oApp = CreateObject("Word.Application")
Set oDoc = oApp.Documents.Add(Path & Temp)

Call setBM(oDoc, "DocName", strDocName)
Call setBM(oDoc, "Author", Author)
Call setBM(oDoc, "Date", dtDate)
Call setBM(oDoc, "Revision", Revision)

***type mismatch on return?? or at 'BMRange =' line****
oApp.Selection.Goto wdGoToBookmark, Name:="StartHere"
oApp.Visible = True

GoTo exit1:

Err_Edit:
MsgBox Err.Description
MsgBox Err.source
Resume exit1:

exit1:
End Function

Sub setBM(objDoc As Object, strBookMark As String,
strText As Variant)

Set objDoc = ActiveDocument
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(strBookMark).Range
BMRange.Text = strText **type mismatch error***
ActiveDocument.Bookmarks.Add strBookMark, BMRange

End Sub
 
T

Tammy

I will try that! However, here is why I have it set to
variant - maybe you have another suggestion in reference
to this! One of the items passed is a date field. I
started changing all those to "string", but thought that
would mess me up somewhere else, and wouldn't
be "correct" - so, what do you suggest?

Thanks!
 
T

Tammy

I will try that! However, here is why I have it set to
variant - maybe you have another suggestion in reference
to this! One of the items passed is a date field. I
started changing all those to "string", but thought that
would mess me up somewhere else, and wouldn't
be "correct" - so, what do you suggest?

Thanks!
 
T

Tammy

Okay, well, I have tried that, but now I am getting "the
remote server does not exist or is unavailable". I
received this message early on in this project. I do not
remember what it was or what exactly I changed to take
care of this. Where do I go from here?

THANKS!
 
A

Albert D. Kallal

Gee, you might be running a copy of word already?

Does restarting your computer fix this? (after doing a lot of testing, you
might want to do this since when running code and you have a problem, then
often *additinal* copies of word remains in memory).

Also, I never really did like the bookmarks, as they are hard to see, and
users generally have trouble with working with them. I would use real word
merge fields. However, it would seem that you have the need to also "read"
the fields, and thus word merge fields are not the answer.
 
T

Tammy

I haven't restarted my computer, but I have tried 1)
pulling up the task manager and closing out running word
processes and 2)closing the database and starting over.

Yes, I do need to "read" the text that is inserted at one
bookmark for later use. I would like to set it to the
filename. I am guessing that's what you meant
by "read"!? The user is enter some basic information
(basically a title page)in an Access form - we are
tracking that info - but the body of the document still
needs to be created and will be done at that time. There
is one time when the user will not actually open the doc,
the information is just appended on to the end, or to a
section of the form. I will quickly/briefly explore the
option of merge fields, as I have not even considered
them, but if you have a quick answer yes/no - please let
me know! I didn't know if this information changed your
opinion!?

Also, there is something here not "clicking" for me when
I am trying to use VBA in Word - I am just not seeing
the "big picture" or understanding why I can use a
certain bookmark(s) statement with an application object
and not a doc object (I know there is a differenc between
Bookmark and Bookmarks) - are there any good
references/books out there for this???

Thanks again for your time & help!!
 

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