Office 97 Access to Word Automation
Author |
Message |
Dave Lewi #1 / 10
|
 Office 97 Access to Word Automation
I have an application with several table Iam am querying linked with a common key. (FamilyNumber). I am trying to use DAO to point to the query and using the FamilyNumber on an open form as criteria have related fields appear at bookmarks in a Word .dot. Can any one give an idea how the code should look. Thanks
|
Sun, 13 Oct 2002 03:00:00 GMT |
|
 |
1stThingsFirs #2 / 10
|
 Office 97 Access to Word Automation
there is (was?) a good explanation of these issues at the microsoft homepage... www.microsoft.com/officedev
Quote: > I have an application with several table Iam am querying linked with a > common key. (FamilyNumber). I am trying to use DAO to point to the > query and using the FamilyNumber on an open form as criteria have > related fields appear at bookmarks in a Word .dot. > Can any one give an idea how the code should look. > Thanks
|
Sun, 13 Oct 2002 03:00:00 GMT |
|
 |
Sam #3 / 10
|
 Office 97 Access to Word Automation
FYI -- What you are describing is a "mail merge" in Word-speak. And you would be better off using merge fields (tied to their Access source from the Word merge template) in Word rather than bookmarks - unless you want to add/design more custom code to handle Word's bookmarks. Are you creating a new document (*.doc) from a template (*.dot) each time the FamilyNumber changes in the Access form? If so, bookmarks MAY work for you. Just be aware that the type of bookmark (either single-point or a selection) used is going to make a huge difference as to what you can not do with it later. For example, a single point bookmark can be used to place text; however, it is not easy to recover the information that was placed at the bookmark later on unless one captures the extent of the text being placed at each bookmark through some mechanism. Also, a selection bookmark is deleted once data have been placed at that location in the document. IF you are reusing a document (.doc) created from a template, selection bookmarks (as designed by MS) will not work for you. With fields these problems do not occur (and you can use bookmarks other than as marks for text insertion). My suggestion is to use fields and a mail merge approach instead. The work required to change your document is minimal (dependng upon the extent of your document, of course!). If you need help with fields in Word, ask. Sam
| I have an application with several table Iam am querying linked with a | common key. (FamilyNumber). I am trying to use DAO to point to the | query and using the FamilyNumber on an open form as criteria have | related fields appear at bookmarks in a Word .dot. | | Can any one give an idea how the code should look. | | Thanks | | | | |
|
Sun, 13 Oct 2002 03:00:00 GMT |
|
 |
1stThingsFirs #4 / 10
|
 Office 97 Access to Word Automation
You are right, as long as the purpose is mixing a whole lot of records with word text. when outputting only one document, mailmerge is not the way to go, but you would opt for automating word from access. which is, as I said, explained on the Ms site.
Quote: > FYI -- > What you are describing is a "mail merge" in Word-speak. And you would be
better off using merge fields (tied to their Access source Quote: > from the Word merge template) in Word rather than bookmarks - unless you
want to add/design more custom code to handle Word's Quote: > bookmarks. > Are you creating a new document (*.doc) from a template (*.dot) each time
the FamilyNumber changes in the Access form? If so, Quote: > bookmarks MAY work for you. Just be aware that the type of bookmark
(either single-point or a selection) used is going to make a Quote: > huge difference as to what you can not do with it later. > For example, a single point bookmark can be used to place text; however,
it is not easy to recover the information that was placed Quote: > at the bookmark later on unless one captures the extent of the text being
placed at each bookmark through some mechanism. Also, a Quote: > selection bookmark is deleted once data have been placed at that location
in the document. IF you are reusing a document (.doc) Quote: > created from a template, selection bookmarks (as designed by MS) will not
work for you. With fields these problems do not occur (and Quote: > you can use bookmarks other than as marks for text insertion). > My suggestion is to use fields and a mail merge approach instead. The work
required to change your document is minimal (dependng Quote: > upon the extent of your document, of course!). > If you need help with fields in Word, ask. > Sam
Quote: > | I have an application with several table Iam am querying linked with a > | common key. (FamilyNumber). I am trying to use DAO to point to the > | query and using the FamilyNumber on an open form as criteria have > | related fields appear at bookmarks in a Word .dot. > | > | Can any one give an idea how the code should look. > | > | Thanks > | > | > | > | > |
|
Sun, 13 Oct 2002 03:00:00 GMT |
|
 |
Sam #5 / 10
|
 Office 97 Access to Word Automation
Dave did not describe his final goal, so I guess he will choose the method he is most comfortable with. Anyway, since Dave is using Access then, presumably, he has several records - 10 or 1000 or 10000... . He is also using FamilyNumber as a criterion, so it once again is not too much of a stretch that he would like to generate these documents for various FamilyNumber selections. Automating Word from Access and calling on the former's fields & merge feature in VBA is no more diffcult than using bookmarks. Sam
| You are right, as long as the purpose is mixing a whole lot of records with | word text. when outputting only one document, mailmerge is not the way to | go, but you would opt for automating word from access. which is, as I said, | explained on the Ms site. |
| > FYI -- | > | > What you are describing is a "mail merge" in Word-speak. And you would be | better off using merge fields (tied to their Access source | > from the Word merge template) in Word rather than bookmarks - unless you | want to add/design more custom code to handle Word's | > bookmarks. | > | > Are you creating a new document (*.doc) from a template (*.dot) each time | the FamilyNumber changes in the Access form? If so, | > bookmarks MAY work for you. Just be aware that the type of bookmark | (either single-point or a selection) used is going to make a | > huge difference as to what you can not do with it later. | > | > For example, a single point bookmark can be used to place text; however, | it is not easy to recover the information that was placed | > at the bookmark later on unless one captures the extent of the text being | placed at each bookmark through some mechanism. Also, a | > selection bookmark is deleted once data have been placed at that location | in the document. IF you are reusing a document (.doc) | > created from a template, selection bookmarks (as designed by MS) will not | work for you. With fields these problems do not occur (and | > you can use bookmarks other than as marks for text insertion). | > | > | > My suggestion is to use fields and a mail merge approach instead. The work | required to change your document is minimal (dependng | > upon the extent of your document, of course!). | > | > If you need help with fields in Word, ask. | > | > | > Sam | > | > | >
| > | I have an application with several table Iam am querying linked with a | > | common key. (FamilyNumber). I am trying to use DAO to point to the | > | query and using the FamilyNumber on an open form as criteria have | > | related fields appear at bookmarks in a Word .dot. | > | | > | Can any one give an idea how the code should look. | > | | > | Thanks | > | | > | | > | | > | | > | | > | > | |
|
Sun, 13 Oct 2002 03:00:00 GMT |
|
 |
Dave Lewi #6 / 10
|
 Office 97 Access to Word Automation
Gentlemen, What i am after is to be able to select a specific Familynumber and display information relating to that familynumber from several tables within a Word document. the Word documnet will have generic text with the family information inserted in the documnet at the correct points. I have not tried the mail merge and it seems like an easier way to go but Iam not sure how to restrict the information to just the desired familynumber. Any help would be greatly appreciated. Thanks Dave Quote:
> Dave did not describe his final goal, so I guess he will choose the method he is most comfortable with. > Anyway, since Dave is using Access then, presumably, he has several records - 10 or 1000 or 10000... . He is also using FamilyNumber > as a criterion, so it once again is not too much of a stretch that he would like to generate these documents for various > FamilyNumber selections. > Automating Word from Access and calling on the former's fields & merge feature in VBA is no more diffcult than using bookmarks. > Sam
> | You are right, as long as the purpose is mixing a whole lot of records with > | word text. when outputting only one document, mailmerge is not the way to > | go, but you would opt for automating word from access. which is, as I said, > | explained on the Ms site. > |
> | > FYI -- > | > > | > What you are describing is a "mail merge" in Word-speak. And you would be > | better off using merge fields (tied to their Access source > | > from the Word merge template) in Word rather than bookmarks - unless you > | want to add/design more custom code to handle Word's > | > bookmarks. > | > > | > Are you creating a new document (*.doc) from a template (*.dot) each time > | the FamilyNumber changes in the Access form? If so, > | > bookmarks MAY work for you. Just be aware that the type of bookmark > | (either single-point or a selection) used is going to make a > | > huge difference as to what you can not do with it later. > | > > | > For example, a single point bookmark can be used to place text; however, > | it is not easy to recover the information that was placed > | > at the bookmark later on unless one captures the extent of the text being > | placed at each bookmark through some mechanism. Also, a > | > selection bookmark is deleted once data have been placed at that location > | in the document. IF you are reusing a document (.doc) > | > created from a template, selection bookmarks (as designed by MS) will not > | work for you. With fields these problems do not occur (and > | > you can use bookmarks other than as marks for text insertion). > | > > | > > | > My suggestion is to use fields and a mail merge approach instead. The work > | required to change your document is minimal (dependng > | > upon the extent of your document, of course!). > | > > | > If you need help with fields in Word, ask. > | > > | > > | > Sam > | > > | > > | >
> | > | I have an application with several table Iam am querying linked with a > | > | common key. (FamilyNumber). I am trying to use DAO to point to the > | > | query and using the FamilyNumber on an open form as criteria have > | > | related fields appear at bookmarks in a Word .dot. > | > | > | > | Can any one give an idea how the code should look. > | > | > | > | Thanks > | > | > | > | > | > | > | > | > | > | > | > > | > > | > |
|
Mon, 14 Oct 2002 03:00:00 GMT |
|
 |
Sam #7 / 10
|
 Office 97 Access to Word Automation
Dave: Are you using Word as a display mechanism only? Will you be printing docs for available records - what you are describing in effect seems like a form document? The way a mail merge works is: 1. You create a document - you already have this. 2. You convert it to a mail merge document (Tools-MailMerge) - set the data source file/table etc. 3. Insert the merge fields from the source query (in your case where data from multiple tables are being displayed), and save the merge document (as a template?) 4. If you are in Word, you can run the Tools--MailMerge option and specify the query criterion of FamilyNumber and have a new document created (among other options) To control everything from Access, still requires Steps 1 to 3. You can do the rest from Access, by setting a ref to Word, opening the document via automation, and merging from within Access. See code snippet below. <SNIP> Dim oWord as Word.Application Dim oWordDoc as Word.Document Dim oWordMerge as Word.MailMerge Dim strFullNameSource as String On Error Resume Next Set oWord = GetObject(, "Word.Application") If oWord Is Nothing Then Set oWord = CreateObject("Word.Application") End If oWord.Visible = True Set oWordDoc = oWord.Documents.Open(strFullNameSource) oWordDoc.MailMerge.DataSource.QueryString = _ 'Change references to your merge document and form field. 'The following on one line "SELECT * FROM [MyMultiTableQuery] WHERE (([FamilyNumber] = " & Forms!MyForm!FamilyNumber & "))" & "" 'Now merge Set oWordMerge = oWordDoc.MailMerge If oWordMerge.State = wdMainAndDataSource Then oWordMerge.Execute <SNIP> Sam
| Gentlemen, | What i am after is to be able to select a specific Familynumber and display information relating to that familynumber from several | tables within a Word document. the Word documnet will have generic text with the family information inserted in the documnet at the | correct points. I have not tried the mail merge and it seems like an easier way to go but Iam not sure how to restrict the information | to just the desired familynumber. | | Any help would be greatly appreciated. | | Thanks | Dave | | |
| | > Dave did not describe his final goal, so I guess he will choose the method he is most comfortable with. | > | > Anyway, since Dave is using Access then, presumably, he has several records - 10 or 1000 or 10000... . He is also using FamilyNumber | > as a criterion, so it once again is not too much of a stretch that he would like to generate these documents for various | > FamilyNumber selections. | > | > Automating Word from Access and calling on the former's fields & merge feature in VBA is no more diffcult than using bookmarks. | > | > Sam | >
| > | You are right, as long as the purpose is mixing a whole lot of records with | > | word text. when outputting only one document, mailmerge is not the way to | > | go, but you would opt for automating word from access. which is, as I said, | > | explained on the Ms site. | > |
| > | > FYI -- | > | > | > | > What you are describing is a "mail merge" in Word-speak. And you would be | > | better off using merge fields (tied to their Access source | > | > from the Word merge template) in Word rather than bookmarks - unless you | > | want to add/design more custom code to handle Word's | > | > bookmarks. | > | > | > | > Are you creating a new document (*.doc) from a template (*.dot) each time | > | the FamilyNumber changes in the Access form? If so, | > | > bookmarks MAY work for you. Just be aware that the type of bookmark | > | (either single-point or a selection) used is going to make a | > | > huge difference as to what you can not do with it later. | > | > | > | > For example, a single point bookmark can be used to place text; however, | > | it is not easy to recover the information that was placed | > | > at the bookmark later on unless one captures the extent of the text being | > | placed at each bookmark through some mechanism. Also, a | > | > selection bookmark is deleted once data have been placed at that location | > | in the document. IF you are reusing a document (.doc) | > | > created from a template, selection bookmarks (as designed by MS) will not | > | work for you. With fields these problems do not occur (and | > | > you can use bookmarks other than as marks for text insertion). | > | > | > | > | > | > My suggestion is to use fields and a mail merge approach instead. The work | > | required to change your document is minimal (dependng | > | > upon the extent of your document, of course!). | > | > | > | > If you need help with fields in Word, ask. | > | > | > | > | > | > Sam | > | > | > | > | > | >
| > | > | I have an application with several table Iam am querying linked with a | > | > | common key. (FamilyNumber). I am trying to use DAO to point to the | > | > | query and using the FamilyNumber on an open form as criteria have | > | > | related fields appear at bookmarks in a Word .dot. | > | > | | > | > | Can any one give an idea how the code should look. | > | > | | > | > | Thanks | > | > | | > | > | | > | > | | > | > | | > | > | | > | > | > | > | > | | > | |
|
Mon, 14 Oct 2002 03:00:00 GMT |
|
 |
1stThingsFirs #8 / 10
|
 Office 97 Access to Word Automation
You are right. I am using the way I described, to generate a contract for one of the numerous companies in my database. I think that's the easiest way, since the possibilities of mailmerge are not used here. But, Dave can now chose between both methods... :)
Quote: > Dave did not describe his final goal, so I guess he will choose the method
he is most comfortable with. Quote: > Anyway, since Dave is using Access then, presumably, he has several
records - 10 or 1000 or 10000... . He is also using FamilyNumber Quote: > as a criterion, so it once again is not too much of a stretch that he
would like to generate these documents for various Quote: > FamilyNumber selections. > Automating Word from Access and calling on the former's fields & merge
feature in VBA is no more diffcult than using bookmarks. Quote:
Quote: > | You are right, as long as the purpose is mixing a whole lot of records with > | word text. when outputting only one document, mailmerge is not the way to > | go, but you would opt for automating word from access. which is, as I said, > | explained on the Ms site. > |
> | > FYI -- > | > > | > What you are describing is a "mail merge" in Word-speak. And you would be > | better off using merge fields (tied to their Access source > | > from the Word merge template) in Word rather than bookmarks - unless you > | want to add/design more custom code to handle Word's > | > bookmarks. > | > > | > Are you creating a new document (*.doc) from a template (*.dot) each time > | the FamilyNumber changes in the Access form? If so, > | > bookmarks MAY work for you. Just be aware that the type of bookmark > | (either single-point or a selection) used is going to make a > | > huge difference as to what you can not do with it later. > | > > | > For example, a single point bookmark can be used to place text; however, > | it is not easy to recover the information that was placed > | > at the bookmark later on unless one captures the extent of the text being > | placed at each bookmark through some mechanism. Also, a > | > selection bookmark is deleted once data have been placed at that location > | in the document. IF you are reusing a document (.doc) > | > created from a template, selection bookmarks (as designed by MS) will not > | work for you. With fields these problems do not occur (and > | > you can use bookmarks other than as marks for text insertion). > | > > | > > | > My suggestion is to use fields and a mail merge approach instead. The work > | required to change your document is minimal (dependng > | > upon the extent of your document, of course!). > | > > | > If you need help with fields in Word, ask. > | > > | > > | > Sam > | > > | > > | >
> | > | I have an application with several table Iam am querying linked with a > | > | common key. (FamilyNumber). I am trying to use DAO to point to the > | > | query and using the FamilyNumber on an open form as criteria have > | > | related fields appear at bookmarks in a Word .dot. > | > | > | > | Can any one give an idea how the code should look. > | > | > | > | Thanks > | > | > | > | > | > | > | > | > | > | > | > > | > > | > |
|
Sat, 19 Oct 2002 03:00:00 GMT |
|
 |
Dave Lewi #9 / 10
|
 Office 97 Access to Word Automation
Sam, I tried to use the mail merge but it does not seem to fill my requirements. I have use the following code to open Word from within access but now require that the values displayed from a query synchronized with the familynumber selected in a combo box on an open form and the specific values for each field placed in pretyped word doc or dot at various bookmark insertion points. Public Function CreateWordDocument() ' Open a Word and insert text - used by menu command. Dim appWord As Word.Application ' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' Switch to Microsoft Word so it won't go away when you finish. On Error Resume Next AppActivate "Microsoft Word" ' If Word isn't running, start and activate it. If Err Then Shell "C:\Program files\Microsoft Office\Office\" _ & "Winword /Automation", vbMaximizedFocus AppActivate "Microsoft Word" End If On Error GoTo 0 ' Get an Application object so you can automate Word. Set appWord = GetObject(, "Word.Application") ' Open a document based on the OverviewDocumnet.doc, turn off the ' automatic spell check, and move to the MemotoLine bookmark. With appWord .Documents.Add "C:\My Documents\Access\Bright\1999\OverviewDoc.Doc" .ActiveDocument.ShowSpellingErrors = False .Selection.Goto wdGoToBookmark, Name:="DOCOVFamilyName" End With End Function Any Help from this point please. Quote:
> Dave: > Are you using Word as a display mechanism only? Will you be printing docs for available records - what you are describing in effect > seems like a form document? > The way a mail merge works is: > 1. You create a document - you already have this. > 2. You convert it to a mail merge document (Tools-MailMerge) - set the data source file/table etc. > 3. Insert the merge fields from the source query (in your case where data from multiple tables are being displayed), and save the > merge document (as a template?) > 4. If you are in Word, you can run the Tools--MailMerge option and specify the query criterion of FamilyNumber and have a new > document created (among other options) > To control everything from Access, still requires Steps 1 to 3. You can do the rest from Access, by setting a ref to Word, opening > the document via automation, and merging from within Access. See code snippet below. > <SNIP> > Dim oWord as Word.Application > Dim oWordDoc as Word.Document > Dim oWordMerge as Word.MailMerge > Dim strFullNameSource as String > On Error Resume Next > Set oWord = GetObject(, "Word.Application") > If oWord Is Nothing Then > Set oWord = CreateObject("Word.Application") > End If > oWord.Visible = True > Set oWordDoc = oWord.Documents.Open(strFullNameSource) > oWordDoc.MailMerge.DataSource.QueryString = _ > 'Change references to your merge document and form field. > 'The following on one line > "SELECT * FROM [MyMultiTableQuery] WHERE (([FamilyNumber] = " & Forms!MyForm!FamilyNumber & "))" & "" > 'Now merge > Set oWordMerge = oWordDoc.MailMerge > If oWordMerge.State = wdMainAndDataSource Then oWordMerge.Execute > <SNIP> > Sam
> | Gentlemen, > | What i am after is to be able to select a specific Familynumber and display information relating to that familynumber from several > | tables within a Word document. the Word documnet will have generic text with the family information inserted in the documnet at > the > | correct points. I have not tried the mail merge and it seems like an easier way to go but Iam not sure how to restrict the > information > | to just the desired familynumber. > | > | Any help would be greatly appreciated. > | > | Thanks > | Dave > | > | > |
> | > | > Dave did not describe his final goal, so I guess he will choose the method he is most comfortable with. > | > > | > Anyway, since Dave is using Access then, presumably, he has several records - 10 or 1000 or 10000... . He is also using > FamilyNumber > | > as a criterion, so it once again is not too much of a stretch that he would like to generate these documents for various > | > FamilyNumber selections. > | > > | > Automating Word from Access and calling on the former's fields & merge feature in VBA is no more diffcult than using bookmarks. > | > > | > Sam > | >
> | > | You are right, as long as the purpose is mixing a whole lot of records with > | > | word text. when outputting only one document, mailmerge is not the way to > | > | go, but you would opt for automating word from access. which is, as I said, > | > | explained on the Ms site. > | > |
> | > | > FYI -- > | > | > > | > | > What you are describing is a "mail merge" in Word-speak. And you would be > | > | better off using merge fields (tied to their Access source > | > | > from the Word merge template) in Word rather than bookmarks - unless you > | > | want to add/design more custom code to handle Word's > | > | > bookmarks. > | > | > > | > | > Are you creating a new document (*.doc) from a template (*.dot) each time > | > | the FamilyNumber changes in the Access form? If so, > | > | > bookmarks MAY work for you. Just be aware that the type of bookmark > | > | (either single-point or a selection) used is going to make a > | > | > huge difference as to what you can not do with it later. > | > | > > | > | > For example, a single point bookmark can be used to place text; however, > | > | it is not easy to recover the information that was placed > | > | > at the bookmark later on unless one captures the extent of the text being > | > | placed at each bookmark through some mechanism. Also, a > | > | > selection bookmark is deleted once data have been placed at that location > | > | in the document. IF you are reusing a document (.doc) > | > | > created from a template, selection bookmarks (as designed by MS) will not > | > | work for you. With fields these problems do not occur (and > | > | > you can use bookmarks other than as marks for text insertion). > | > | > > | > | > > | > | > My suggestion is to use fields and a mail merge approach instead. The work > | > | required to change your document is minimal (dependng > | > | > upon the extent of your document, of course!). > | > | > > | > | > If you need help with fields in Word, ask. > | > | > > | > | > > | > | > Sam > | > | > > | > | > > | > | >
> | > | > | I have an application with several table Iam am querying linked with a > | > | > | common key. (FamilyNumber). I am trying to use DAO to point to the > | > | > | query and using the FamilyNumber on an open form as criteria have > | > | > | related fields appear at bookmarks in a Word .dot. > | > | > | > | > | > | Can any one give an idea how the code should look. > | > | > | > | > | > | Thanks > | > | > | > | > | > | > | > | > | > | > | > | > | > | > | > | > | > > | > | > > | > | > | > | > |
|
Sun, 20 Oct 2002 03:00:00 GMT |
|
 |
1stThingsFirs #10 / 10
|
 Office 97 Access to Word Automation
Quote: > I tried to use the mail merge but it does not seem to fill my requirements. > I have use the following code to open Word from within access but now
require that the values displayed from a query synchronized with Quote: > the familynumber selected in a combo box on an open form and the specific
values for each field placed in pretyped word doc or dot at Quote: > various bookmark insertion points.
if you are using bookmark insertion points, you should jump to the bookmark-place, and use typetext afterwards. look at code which I use ... variables are in dutch, but are probably understandable, even if you don't know what they mean... --- Function xxx() Dim db As Database Dim factuurgegevens As Recordset Dim wapp As Word.Application Dim eurobedrag, BTWBedrag, TotaalZonderBTW, TotaalMetBTW As Integer Dim t As Integer Dim factuurgegevensSQL As String Dim templatenaam As String Set db = CurrentDb 'define template which will be used in Word templatename = "G:\challenge\databank\factuur.dot" 'define query, 'this query can be depending upon the values in a form. factuurgegevensSQL = "SELECT facturen.factuurnummer, bedrijven.[company name], bedrijven.address, bedrijven.postalcode, bedrijven.town FROM facturen" Set factuurgegevens = db.OpenRecordset(factuurgegevensSQL) 'see if Word is open Set wapp = GetObject(, "word.application") 'if wapp=nothing, word is not open 'a new word has to be opened If wapp Is Nothing Then Set wapp = New Word.Application End If 'open document with that template, defined above wapp.Documents.Add Template:=templatename, NewTemplate:=False With wapp.Selection .Goto what:=wdGoToBookmark, Name:="company name" .TypeText factuurgegevens!company name .Goto what:=wdGoToBookmark, Name:="address" .TypeText factuurgegevens!address .Goto what:=wdGoToBookmark, Name:="town" .TypeText factuurgegevens!postalcode & " " & factuurgegevens!town etc.... Hope this helps... Quote: > Public Function CreateWordDocument() > ' Open a Word and insert text - used by menu command. > Dim appWord As Word.Application > '
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + Quote: > ' Switch to Microsoft Word so it won't go away when you finish. > On Error Resume Next > AppActivate "Microsoft Word" > ' If Word isn't running, start and activate it. > If Err Then > Shell "C:\Program files\Microsoft Office\Office\" _ > & "Winword /Automation", vbMaximizedFocus > AppActivate "Microsoft Word" > End If > On Error GoTo 0 > ' Get an Application object so you can automate Word. > Set appWord = GetObject(, "Word.Application") > ' Open a document based on the OverviewDocumnet.doc, turn off the > ' automatic spell check, and move to the MemotoLine bookmark. > With appWord > .Documents.Add "C:\My Documents\Access\Bright\1999\OverviewDoc.Doc" > .ActiveDocument.ShowSpellingErrors = False > .Selection.Goto wdGoToBookmark, Name:="DOCOVFamilyName" > End With > End Function > Any Help from this point please.
> > Dave: > > Are you using Word as a display mechanism only? Will you be printing
docs for available records - what you are describing in effect Quote: > > seems like a form document? > > The way a mail merge works is: > > 1. You create a document - you already have this. > > 2. You convert it to a mail merge document (Tools-MailMerge) - set the
data source file/table etc. Quote: > > 3. Insert the merge fields from the source query (in your case where
data from multiple tables are being displayed), and save the Quote: > > merge document (as a template?) > > 4. If you are in Word, you can run the Tools--MailMerge option and
specify the query criterion of FamilyNumber and have a new Quote: > > document created (among other options) > > To control everything from Access, still requires Steps 1 to 3. You can
do the rest from Access, by setting a ref to Word, opening Quote: > > the document via automation, and merging from within Access. See code snippet below. > > <SNIP> > > Dim oWord as Word.Application > > Dim oWordDoc as Word.Document > > Dim oWordMerge as Word.MailMerge > > Dim strFullNameSource as String > > On Error Resume Next > > Set oWord = GetObject(, "Word.Application") > > If oWord Is Nothing Then > > Set oWord = CreateObject("Word.Application") > > End If > > oWord.Visible = True > > Set oWordDoc = oWord.Documents.Open(strFullNameSource) > > oWordDoc.MailMerge.DataSource.QueryString = _ > > 'Change references to your merge document and form field. > > 'The following on one line > > "SELECT * FROM [MyMultiTableQuery] WHERE (([FamilyNumber] = " &
Forms!MyForm!FamilyNumber & "))" & "" Quote: > > 'Now merge > > Set oWordMerge = oWordDoc.MailMerge > > If oWordMerge.State = wdMainAndDataSource Then oWordMerge.Execute > > <SNIP> > > Sam
Quote: > > | Gentlemen, > > | What i am after is to be able to select a specific Familynumber and
display information relating to that familynumber from several Quote: > > | tables within a Word document. the Word documnet will have generic
text with the family information inserted in the documnet at Quote: > > the > > | correct points. I have not tried the mail merge and it seems like an
easier way to go but Iam not sure how to restrict the Quote: > > information > > | to just the desired familynumber. > > | > > | Any help would be greatly appreciated. > > | > > | Thanks > > | Dave > > | > > | > > |
> > | > > | > Dave did not describe his final goal, so I guess he will choose the
method he is most comfortable with. Quote: > > | > > > | > Anyway, since Dave is using Access then, presumably, he has several
records - 10 or 1000 or 10000... . He is also using Quote: > > FamilyNumber > > | > as a criterion, so it once again is not too much of a stretch that
he would like to generate these documents for various Quote: > > | > FamilyNumber selections. > > | > > > | > Automating Word from Access and calling on the former's fields &
merge feature in VBA is no more diffcult than using bookmarks. Quote: > > | > > > | > Sam > > | >
Quote: > > | > | You are right, as long as the purpose is mixing a whole lot of records with > > | > | word text. when outputting only one document, mailmerge is not the way to > > | > | go, but you would opt for automating word from access. which is, as I said, > > | > | explained on the Ms site. > > | > |
> > | > | > FYI -- > > | > | > > > | > | > What you are describing is a "mail merge" in Word-speak. And you would be > > | > | better off using merge fields (tied to their Access source > > | > | > from the Word merge template) in Word rather than bookmarks - unless you > > | > | want to add/design more custom code to handle Word's > > | > | > bookmarks. > > | > | > > > | > | > Are you creating a new document (*.doc) from a template (*.dot) each time > > | > | the FamilyNumber changes in the Access form? If so, > > | > | > bookmarks MAY work for you. Just be aware that the type of bookmark > > | > | (either single-point or a selection) used is going to make a > > | > | > huge difference as to what you can not do with it later. > > | > | > > > | > | > For example, a single point bookmark can be used to place text; however, > > | > | it is not easy to recover the information that was placed > > | > | > at the bookmark later on unless one captures the extent of the text being > > | > | placed at each bookmark through some mechanism. Also, a > > | > | > selection bookmark is deleted once data have been placed at that location > > | > | in the document. IF you are reusing a document (.doc) > > | > | > created from a template, selection bookmarks (as designed by MS) will not > > | > | work for you. With fields these problems do not occur (and > > | > | > you can use bookmarks other than as marks for text insertion). > > | > | > > > | > | > > > | > | > My suggestion is to use fields and a mail merge approach instead. The work > > | > | required to change your document is minimal (dependng > > | > | > upon the extent of your document, of course!). > > | > | > > > | > | > If you need help with fields in Word, ask. > > | > | > > > | > | > > > | > | > Sam > > | > | > > > | > | > > > | > | >
> > | > | > | I have an application with several table Iam am querying linked with a > > | > | > | common key. (FamilyNumber). I am trying to use DAO to point to the > > | > | > | query and using the FamilyNumber on an open form as criteria have > > | > | > | related fields appear at bookmarks in a Word .dot. > > | > | > | > > | > | > | Can any one give an idea how the code should look. > > | > | > | > > | > | > | Thanks > > | > | > | > > | > | > | > > | > | > | > > | > | > | > > | > | > | > > | > | > > > | > | > > > | > | > > | > | > > |
|
Mon, 21 Oct 2002 03:00:00 GMT |
|
|
|