Passing string variable from access 2000 to word 2000

F

fpilot

Need to pass a string (ex: Ticket = 2582873) from access
to a word document I open from access. I need to take
this ticket_no.value in access 2000 to be available to
pass to my code in the word document. Any ideas. Below
is an example of code I'm using to open the word document
from access.

Dim x As Object
Dim y As String
Dim z As Object

NUM = NEW_EMPLOYEE_NO
Set x = CreateObject("Word.application")
x.Visible = True
x.Documents.Open ("p:\Welcomeoriginal.dot")

Thanks in advance.
 
C

Cindy M -WordMVP-

Hi Fpilot,

1. Use the Documents.ADD method to create a documetn from a
template (*.dot)

2. Do you need to place this string into a target? Have you
defined that target, yet? Generally, one uses bookmarks to
set "targets" in a Word document. Insert/Bookmark

3. In this case, the basic code would be

Dim doc as Word.Document

Set x = CreateObject("Word.application")
x.Visible = True
Set doc = x.Documents.Add("p:\Welcomeoriginal.dot")
doc.Bookmarks("TheName").Range.Text = y
Need to pass a string (ex: Ticket = 2582873) from access
to a word document I open from access. I need to take
this ticket_no.value in access 2000 to be available to
pass to my code in the word document. Any ideas. Below
is an example of code I'm using to open the word document
from access.

Dim x As Object
Dim y As String
Dim z As Object

NUM = NEW_EMPLOYEE_NO
Set x = CreateObject("Word.application")
x.Visible = True
x.Documents.Open ("p:\Welcomeoriginal.dot")

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
G

Guest

This works great...but I need to take the variable that
you stored in the bookmark and store it as a variable
within the word document, cause I wrote code to merge the
document against the database based on that ticket_no.

Example of my code within word below...maybe this will
help. What I need is that ticket # of the record I was on
in access passed through to word to place in the ticket No
area below.

Sub MergeDoc()
'TN being the ticket number that was passed from access
Dim TN As String

ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT * FROM [dbo_Test] WHERE (([TICKET_NO]
= '273510 '))" & _
""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With

End Sub

Thanks in advance.
 
C

Cindy M -WordMVP-

I'm sorry, I'm not understanding your question. You neglected
to mention in your original message that you're using mail
merge, which changes things.

1. If the ticket number is part of the data source record
(according to the QueryString you show, it is), then why not
simply insert the relevant MergeField into the document?

2. You use the phrase "store it as a variable within the Word
document". Are you using the term "variable" as meaning a
Word document variable? Or do you mean something else?

3. And do you want to store this information in the main
merge document or in the result document? And to what
purpose?
This works great...but I need to take the variable that
you stored in the bookmark and store it as a variable
within the word document, cause I wrote code to merge the
document against the database based on that ticket_no.

Example of my code within word below...maybe this will
help. What I need is that ticket # of the record I was on
in access passed through to word to place in the ticket No
area below.

Sub MergeDoc()
'TN being the ticket number that was passed from access
Dim TN As String

ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT * FROM [dbo_Test] WHERE (([TICKET_NO]
= '273510 '))" & _
""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With

End Sub

Thanks in advance.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

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