From: bryan on
Maybe I should use the term arguments rather than parameters.

Currently I have a working template that when users open it has an OCX
Desktop connection to a database which has a file number. With that number I
can then sql other database files and populate the new document.
What I'd like to do is streamline the process and call the template from a
workflow. Within that workflow task I have a file number which I would use to
sql other databases and populate the doc.

Is this possible?

Thanks,
Bryan



"Peter Jamieson" wrote:

> I'm not completely sure what you are driving at, but...
>
> > Set objWord = objWordApp.Documents.Add("TemplateName")
>
> ....I guess it's obvious that the only "variables" in there - are
> - objWord
> - the mechanism you are using to create the new document
> - the template name, and by extension, anything that you can store in
> that template that you can then reference using VBA.
>
> In other words, if you want to access /different data/ depending on
> which /template/ you base your document on, then what you probably need
> to do is store the relevant connection information in your template. One
> way to do that would be create Word Document variables in your template
> that stored the information necessary to connect to a particular
> database and retrieve information from it.
>
> For example, suppose each template had two document variables as follows:
> a. DSConnection, storing an OLE DB connection string that would let
> you use ADO to open a particular SQL Server database
> b. DSCommand, storing a SQL SELECT statement that would let you open
> an ADO Recordset
>
> then you could use
>
> objWord.Variables("DSConnection")
>
> to extract the connection string,
>
> objWord.Variables("DSCommand")
>
> to extract the SQL (or whatever) statement, and use ADO to get the data
> you need.
>
> That would mean that each /template/ could be used to open a different
> data source. But if you need to do something different every time you
> create a new document, it isn't clear where the data is that would make
> you do thing "X" one time and thing "Y" the next - maybe you could try
> to spell that out.
>
> Peter Jamieson
>
> http://tips.pjmsn.me.uk
>
> On 21/01/2010 17:40, bryan wrote:
> > Posting again as I do not see this post.....
> > In order to get info from other systems, I need some info to start the sql
> > with.
> >
> > Is it possible to pass in variable(s) when doing this:
> > Set objWord = objWordApp.Documents.Add("TemplateName")
> >
> >
> > Thanks,
> > Bryan
> >
> >
> > "Fumei2 via OfficeKB.com" wrote:
> >
> >> Yes you can action the formfields.
> >>
> >> If you are creating a document from a template then use Document_New in the
> >> template.
> >>
> >> bryan wrote:
> >>> Since this template is locked and has formfields I'm assuming then that I
> >>> could tap into other systems to the populate the formfields, Correct?
> >>>
> >>> Also,
> >>> would it be auto(new) or document(new) ?
> >>>
> >>> Thanks,
> >>> Bryan
> >>>
> >>>> Use
> >>>>
> >>> [quoted text clipped - 51 lines]
> >>>>>>> Any idea of why this is happening?
> >>>>>> .
> >>
> >> --
> >> Message posted via OfficeKB.com
> >> http://www.officekb.com/Uwe/Forums.aspx/word-programming/201001/1
> >>
> >> .
> >>
> .
>
From: Peter Jamieson on
> Currently I have a working template that when users open it has an OCX
> Desktop connection

Can you spell out what this is, exactly? I mean, the user opens the
template (or maybe creates a new document based on it). But what is the
OCX in this case (are we talking an OCX control/ActiveX object, or
something else that you know as an OCX)?

Peter Jamieson

http://tips.pjmsn.me.uk

On 21/01/2010 21:31, bryan wrote:
> Maybe I should use the term arguments rather than parameters.
>
> Currently I have a working template that when users open it has an OCX
> Desktop connection to a database which has a file number. With that number I
> can then sql other database files and populate the new document.
> What I'd like to do is streamline the process and call the template from a
> workflow. Within that workflow task I have a file number which I would use to
> sql other databases and populate the doc.
>
> Is this possible?
>
> Thanks,
> Bryan
>
>
>
> "Peter Jamieson" wrote:
>
>> I'm not completely sure what you are driving at, but...
>>
>> > Set objWord = objWordApp.Documents.Add("TemplateName")
>>
>> ....I guess it's obvious that the only "variables" in there - are
>> - objWord
>> - the mechanism you are using to create the new document
>> - the template name, and by extension, anything that you can store in
>> that template that you can then reference using VBA.
>>
>> In other words, if you want to access /different data/ depending on
>> which /template/ you base your document on, then what you probably need
>> to do is store the relevant connection information in your template. One
>> way to do that would be create Word Document variables in your template
>> that stored the information necessary to connect to a particular
>> database and retrieve information from it.
>>
>> For example, suppose each template had two document variables as follows:
>> a. DSConnection, storing an OLE DB connection string that would let
>> you use ADO to open a particular SQL Server database
>> b. DSCommand, storing a SQL SELECT statement that would let you open
>> an ADO Recordset
>>
>> then you could use
>>
>> objWord.Variables("DSConnection")
>>
>> to extract the connection string,
>>
>> objWord.Variables("DSCommand")
>>
>> to extract the SQL (or whatever) statement, and use ADO to get the data
>> you need.
>>
>> That would mean that each /template/ could be used to open a different
>> data source. But if you need to do something different every time you
>> create a new document, it isn't clear where the data is that would make
>> you do thing "X" one time and thing "Y" the next - maybe you could try
>> to spell that out.
>>
>> Peter Jamieson
>>
>> http://tips.pjmsn.me.uk
>>
>> On 21/01/2010 17:40, bryan wrote:
>>> Posting again as I do not see this post.....
>>> In order to get info from other systems, I need some info to start the sql
>>> with.
>>>
>>> Is it possible to pass in variable(s) when doing this:
>>> Set objWord = objWordApp.Documents.Add("TemplateName")
>>>
>>>
>>> Thanks,
>>> Bryan
>>>
>>>
>>> "Fumei2 via OfficeKB.com" wrote:
>>>
>>>> Yes you can action the formfields.
>>>>
>>>> If you are creating a document from a template then use Document_New in the
>>>> template.
>>>>
>>>> bryan wrote:
>>>>> Since this template is locked and has formfields I'm assuming then that I
>>>>> could tap into other systems to the populate the formfields, Correct?
>>>>>
>>>>> Also,
>>>>> would it be auto(new) or document(new) ?
>>>>>
>>>>> Thanks,
>>>>> Bryan
>>>>>
>>>>>> Use
>>>>>>
>>>>> [quoted text clipped - 51 lines]
>>>>>>>>> Any idea of why this is happening?
>>>>>>>> .
>>>>
>>>> --
>>>> Message posted via OfficeKB.com
>>>> http://www.officekb.com/Uwe/Forums.aspx/word-programming/201001/1
>>>>
>>>> .
>>>>
>> .
>>
From: Doug Robbins - Word MVP on
Use the .Result attribute of the formfield to assign a value to it.

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.

"bryan" <bryan(a)discussions.microsoft.com> wrote in message
news:26BB7C9F-D9EA-4B42-8456-AFD68BA5DA7A(a)microsoft.com...
> Another question on this topic:
> Since I want to be able to tap into other systems to populate textfields,
> I
> need some info up front.
> Is it possible to pass in variable(s) on the auto(run)and have them placed
> in
> formfiled(s)?
>
> Once this info is there then I can sql other tables.
>
> Thanks again,
> Bryan
>
> "Fumei2 via OfficeKB.com" wrote:
>
>> Yes you can action the formfields.
>>
>> If you are creating a document from a template then use Document_New in
>> the
>> template.
>>
>> bryan wrote:
>> >Since this template is locked and has formfields I'm assuming then that
>> >I
>> >could tap into other systems to the populate the formfields, Correct?
>> >
>> >Also,
>> >would it be auto(new) or document(new) ?
>> >
>> >Thanks,
>> >Bryan
>> >
>> >> Use
>> >>
>> >[quoted text clipped - 51 lines]
>> >> >> >Any idea of why this is happening?
>> >> >> .
>>
>> --
>> Message posted via OfficeKB.com
>> http://www.officekb.com/Uwe/Forums.aspx/word-programming/201001/1
>>
>> .
>>

From: bryan on
OCX Desktop Control.

Is it possible to pass in args?
If so, how?

Thanks,
Bryan

"Peter Jamieson" wrote:

> > Currently I have a working template that when users open it has an OCX
> > Desktop connection
>
> Can you spell out what this is, exactly? I mean, the user opens the
> template (or maybe creates a new document based on it). But what is the
> OCX in this case (are we talking an OCX control/ActiveX object, or
> something else that you know as an OCX)?
>
> Peter Jamieson
>
> http://tips.pjmsn.me.uk
>
> On 21/01/2010 21:31, bryan wrote:
> > Maybe I should use the term arguments rather than parameters.
> >
> > Currently I have a working template that when users open it has an OCX
> > Desktop connection to a database which has a file number. With that number I
> > can then sql other database files and populate the new document.
> > What I'd like to do is streamline the process and call the template from a
> > workflow. Within that workflow task I have a file number which I would use to
> > sql other databases and populate the doc.
> >
> > Is this possible?
> >
> > Thanks,
> > Bryan
> >
> >
> >
> > "Peter Jamieson" wrote:
> >
> >> I'm not completely sure what you are driving at, but...
> >>
> >> > Set objWord = objWordApp.Documents.Add("TemplateName")
> >>
> >> ....I guess it's obvious that the only "variables" in there - are
> >> - objWord
> >> - the mechanism you are using to create the new document
> >> - the template name, and by extension, anything that you can store in
> >> that template that you can then reference using VBA.
> >>
> >> In other words, if you want to access /different data/ depending on
> >> which /template/ you base your document on, then what you probably need
> >> to do is store the relevant connection information in your template. One
> >> way to do that would be create Word Document variables in your template
> >> that stored the information necessary to connect to a particular
> >> database and retrieve information from it.
> >>
> >> For example, suppose each template had two document variables as follows:
> >> a. DSConnection, storing an OLE DB connection string that would let
> >> you use ADO to open a particular SQL Server database
> >> b. DSCommand, storing a SQL SELECT statement that would let you open
> >> an ADO Recordset
> >>
> >> then you could use
> >>
> >> objWord.Variables("DSConnection")
> >>
> >> to extract the connection string,
> >>
> >> objWord.Variables("DSCommand")
> >>
> >> to extract the SQL (or whatever) statement, and use ADO to get the data
> >> you need.
> >>
> >> That would mean that each /template/ could be used to open a different
> >> data source. But if you need to do something different every time you
> >> create a new document, it isn't clear where the data is that would make
> >> you do thing "X" one time and thing "Y" the next - maybe you could try
> >> to spell that out.
> >>
> >> Peter Jamieson
> >>
> >> http://tips.pjmsn.me.uk
> >>
> >> On 21/01/2010 17:40, bryan wrote:
> >>> Posting again as I do not see this post.....
> >>> In order to get info from other systems, I need some info to start the sql
> >>> with.
> >>>
> >>> Is it possible to pass in variable(s) when doing this:
> >>> Set objWord = objWordApp.Documents.Add("TemplateName")
> >>>
> >>>
> >>> Thanks,
> >>> Bryan
> >>>
> >>>
> >>> "Fumei2 via OfficeKB.com" wrote:
> >>>
> >>>> Yes you can action the formfields.
> >>>>
> >>>> If you are creating a document from a template then use Document_New in the
> >>>> template.
> >>>>
> >>>> bryan wrote:
> >>>>> Since this template is locked and has formfields I'm assuming then that I
> >>>>> could tap into other systems to the populate the formfields, Correct?
> >>>>>
> >>>>> Also,
> >>>>> would it be auto(new) or document(new) ?
> >>>>>
> >>>>> Thanks,
> >>>>> Bryan
> >>>>>
> >>>>>> Use
> >>>>>>
> >>>>> [quoted text clipped - 51 lines]
> >>>>>>>>> Any idea of why this is happening?
> >>>>>>>> .
> >>>>
> >>>> --
> >>>> Message posted via OfficeKB.com
> >>>> http://www.officekb.com/Uwe/Forums.aspx/word-programming/201001/1
> >>>>
> >>>> .
> >>>>
> >> .
> >>
> .
>
From: Peter Jamieson on
I think the simple answer to your question is "no"

I assume that what you are looking for is a way to do something like

OpenTemplate("the template name",thefilenumber)

and have the template's AutoOpen (or whatever) pick up that parameter
and act on it.

However, that's not what you get in the Word environment, because the
procedures that run when you open a template/document or create a
document from a template are initiated by Word, and don't take arguments
(the full range of "how to initiate stuff in Word" can be found at

http://word.mvps.org/FAQs/MacrosVBA/index.htm

)

However, you can
a. use Automation to modify the template/document before the user gets
to work with it
b. call Subs defined in the template/document and pass arguments in
/after/ the document has been created. If you want an "object-oriented
approach where each template has its own processSQL(filenumber) method,
then you can use code like the following:

Sub sample()
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim strDocPath as String
Dim strFileNumber as String
' somewhere in here you need to set up the
' name of the document you want to open
' in strDocPath and the FileNumber in
' strFileNumber

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open(strDocPath)
' approach 1
objDoc.processSQL strFileNumber
' approach 2
objWord.Run "processSQL2" strFileNumber
objDoc.Close
Set objDoc = Nothing
objWord.Quit
Set objWord = Nothing
End Sub

For approach 1 to work, your document needs to have a Sub called
processSQL defined in the "ThisDocument" container. In that case you can
name the parameters how you like.

For approach 2 to work, your document needs a Sub called "processSQL2",
which can be in Module (you can pin down the location using e.g.

objWord.Run "mymodule.processSQL2" strFileNumber

However, to get arguments through to that sub you have to call them
varg1, varg2 etc., e.g.

Sub processSQL2(varg1 As Variant, varg2 As Variant, etc.

There may be other approaches of which I am not aware, but I hope that
gets you a bit further.

Peter Jamieson

http://tips.pjmsn.me.uk

On 22/01/2010 16:09, bryan wrote:
> OCX Desktop Control.
>
> Is it possible to pass in args?
> If so, how?
>
> Thanks,
> Bryan
>
> "Peter Jamieson" wrote:
>
>> > Currently I have a working template that when users open it has an OCX
>> > Desktop connection
>>
>> Can you spell out what this is, exactly? I mean, the user opens the
>> template (or maybe creates a new document based on it). But what is the
>> OCX in this case (are we talking an OCX control/ActiveX object, or
>> something else that you know as an OCX)?
>>
>> Peter Jamieson
>>
>> http://tips.pjmsn.me.uk
>>
>> On 21/01/2010 21:31, bryan wrote:
>>> Maybe I should use the term arguments rather than parameters.
>>>
>>> Currently I have a working template that when users open it has an OCX
>>> Desktop connection to a database which has a file number. With that number I
>>> can then sql other database files and populate the new document.
>>> What I'd like to do is streamline the process and call the template from a
>>> workflow. Within that workflow task I have a file number which I would use to
>>> sql other databases and populate the doc.
>>>
>>> Is this possible?
>>>
>>> Thanks,
>>> Bryan
>>>
>>>
>>>
>>> "Peter Jamieson" wrote:
>>>
>>>> I'm not completely sure what you are driving at, but...
>>>>
>>>> > Set objWord = objWordApp.Documents.Add("TemplateName")
>>>>
>>>> ....I guess it's obvious that the only "variables" in there - are
>>>> - objWord
>>>> - the mechanism you are using to create the new document
>>>> - the template name, and by extension, anything that you can store in
>>>> that template that you can then reference using VBA.
>>>>
>>>> In other words, if you want to access /different data/ depending on
>>>> which /template/ you base your document on, then what you probably need
>>>> to do is store the relevant connection information in your template. One
>>>> way to do that would be create Word Document variables in your template
>>>> that stored the information necessary to connect to a particular
>>>> database and retrieve information from it.
>>>>
>>>> For example, suppose each template had two document variables as follows:
>>>> a. DSConnection, storing an OLE DB connection string that would let
>>>> you use ADO to open a particular SQL Server database
>>>> b. DSCommand, storing a SQL SELECT statement that would let you open
>>>> an ADO Recordset
>>>>
>>>> then you could use
>>>>
>>>> objWord.Variables("DSConnection")
>>>>
>>>> to extract the connection string,
>>>>
>>>> objWord.Variables("DSCommand")
>>>>
>>>> to extract the SQL (or whatever) statement, and use ADO to get the data
>>>> you need.
>>>>
>>>> That would mean that each /template/ could be used to open a different
>>>> data source. But if you need to do something different every time you
>>>> create a new document, it isn't clear where the data is that would make
>>>> you do thing "X" one time and thing "Y" the next - maybe you could try
>>>> to spell that out.
>>>>
>>>> Peter Jamieson
>>>>
>>>> http://tips.pjmsn.me.uk
>>>>
>>>> On 21/01/2010 17:40, bryan wrote:
>>>>> Posting again as I do not see this post.....
>>>>> In order to get info from other systems, I need some info to start the sql
>>>>> with.
>>>>>
>>>>> Is it possible to pass in variable(s) when doing this:
>>>>> Set objWord = objWordApp.Documents.Add("TemplateName")
>>>>>
>>>>>
>>>>> Thanks,
>>>>> Bryan
>>>>>
>>>>>
>>>>> "Fumei2 via OfficeKB.com" wrote:
>>>>>
>>>>>> Yes you can action the formfields.
>>>>>>
>>>>>> If you are creating a document from a template then use Document_New in the
>>>>>> template.
>>>>>>
>>>>>> bryan wrote:
>>>>>>> Since this template is locked and has formfields I'm assuming then that I
>>>>>>> could tap into other systems to the populate the formfields, Correct?
>>>>>>>
>>>>>>> Also,
>>>>>>> would it be auto(new) or document(new) ?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Bryan
>>>>>>>
>>>>>>>> Use
>>>>>>>>
>>>>>>> [quoted text clipped - 51 lines]
>>>>>>>>>>> Any idea of why this is happening?
>>>>>>>>>> .
>>>>>>
>>>>>> --
>>>>>> Message posted via OfficeKB.com
>>>>>> http://www.officekb.com/Uwe/Forums.aspx/word-programming/201001/1
>>>>>>
>>>>>> .
>>>>>>
>>>> .
>>>>
>> .
>>