Export Data to Word

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paolo

    Export Data to Word

    Hello,
    I am trying to create a procedure to export my Access data to a word
    template.
    I would like to export data from two tables to a word file at the same
    time. My two tables are named CASES AND CLIENTS. The word (it is a
    template) is named MASTER
    To store data, I have created two forms named CASES and MASTER. Since
    both forms have a lot of fields, I have added the form CLIENTS as a
    SubForm on the form CASES.

    I have then created bookmarks on my word template and use this code to
    export the data from my table CASES to the template:

    Public Function MASTER()
    Dim dbs As Database, rstCases As Recordset

    Dim appWord As Word.Applicatio n
    Dim intRecordNo As Integer
    Set dbs = CurrentDb()

    Set rstCases = Forms!Cases.Rec ordsetClone
    intRecordNo = Forms!Cases!Rec ordNo
    rstCases.Close

    'OPEN MS WORD
    On Error Resume Next
    AppActivate "Microsoft Word"
    If Err Then
    shell "C:\MSOffice\Of fice\WINWORD.EX E /Automation",
    vbMaximizedFocu s
    AppActivate "Microsoft Word"
    End If
    On Error GoTo 0

    Set appWord = GetObject(, "Word.Applicati on")

    'OPEN THE MASTER TEMPLATE
    With appWord
    ..Documents.Add "C:\MyLibrary\T emplate.dot"
    ..ActiveDocumen t.ShowSpellingE rrors = False
    'INSERT DATA FROM ACCESS TABLE "CASES"
    On Error Resume Next
    ' NAME
    ..Selection.Got o wdGoToBookmark, :="Name"
    ..Selection.Typ eText rstCases!Name & ", " Cases!Name

    My problem is that I am only able to export the data from the table
    CASES to the template.

    I would like to be able to also export the data that I will enter in
    the subform GUESTS into the same template that in the mean time has
    opened as a simple word document (and named document1):

    I have tried to simply add the code:
    ..Selection.Got o wdGoToBookmark, :="Name"
    ..Selection.Typ eText rstCases!Name & ", " Cases!Name

    but it does not work. Obviously I need to declare something. Any idea
    and help with code?

    Thanks.
  • Pieter Linden

    #2
    Re: Export Data to Word

    the Three Amigos do this in the Developer Handbook... you can pass the
    child recordset to the Word doc and then turn that into a table or
    write it to a table... In ADH2000 it's in Chapter 12. See the
    CreateTableFrom Recordset function they wrote. (I'd be nice and post
    it, but I didn't write it...)

    Comment

    • Paolo

      #3
      Re: Export Data to Word

      Thanks friend, but could you provide me with a link where I can find the code?


      pietlinden@hotm ail.com (Pieter Linden) wrote in message news:<bf31e41b. 0310311432.31b2 95d9@posting.go ogle.com>...[color=blue]
      > the Three Amigos do this in the Developer Handbook... you can pass the
      > child recordset to the Word doc and then turn that into a table or
      > write it to a table... In ADH2000 it's in Chapter 12. See the
      > CreateTableFrom Recordset function they wrote. (I'd be nice and post
      > it, but I didn't write it...)[/color]

      Comment

      • Sigurd Bruteig

        #4
        Re: Export Data to Word


        "Paolo" <jprma@tin.it > skrev i melding
        news:9f41a860.0 310310702.3fe29 720@posting.goo gle.com...[color=blue]
        > Hello,
        > I am trying to create a procedure to export my Access data to a word
        > template.
        > I would like to export data from two tables to a word file at the same
        > time. My two tables are named CASES AND CLIENTS. The word (it is a
        > template) is named MASTER
        > To store data, I have created two forms named CASES and MASTER. Since
        > both forms have a lot of fields, I have added the form CLIENTS as a
        > SubForm on the form CASES.
        >
        > I have then created bookmarks on my word template and use this code to
        > export the data from my table CASES to the template:
        >
        > Public Function MASTER()
        > Dim dbs As Database, rstCases As Recordset
        >
        > Dim appWord As Word.Applicatio n
        > Dim intRecordNo As Integer
        > Set dbs = CurrentDb()
        >
        > Set rstCases = Forms!Cases.Rec ordsetClone
        > intRecordNo = Forms!Cases!Rec ordNo
        > rstCases.Close
        >
        > 'OPEN MS WORD
        > On Error Resume Next
        > AppActivate "Microsoft Word"
        > If Err Then
        > shell "C:\MSOffice\Of fice\WINWORD.EX E /Automation",
        > vbMaximizedFocu s
        > AppActivate "Microsoft Word"
        > End If
        > On Error GoTo 0
        >
        > Set appWord = GetObject(, "Word.Applicati on")
        >
        > 'OPEN THE MASTER TEMPLATE
        > With appWord
        > .Documents.Add "C:\MyLibrary\T emplate.dot"
        > .ActiveDocument .ShowSpellingEr rors = False
        > 'INSERT DATA FROM ACCESS TABLE "CASES"
        > On Error Resume Next
        > ' NAME
        > .Selection.Goto wdGoToBookmark, :="Name"
        > .Selection.Type Text rstCases!Name & ", " Cases!Name
        >
        > My problem is that I am only able to export the data from the table
        > CASES to the template.
        >
        > I would like to be able to also export the data that I will enter in
        > the subform GUESTS into the same template that in the mean time has
        > opened as a simple word document (and named document1):
        >
        > I have tried to simply add the code:
        > .Selection.Goto wdGoToBookmark, :="Name"
        > .Selection.Type Text rstCases!Name & ", " Cases!Name
        >
        > but it does not work. Obviously I need to declare something. Any idea
        > and help with code?
        >
        > Thanks.[/color]

        Helen Feddema's website has many codesamples on how to exhange data between
        office application. http://www.helenfeddema.com

        Sigurd


        Comment

        • Pieter Linden

          #5
          Re: Export Data to Word

          It's here. I just found it. Search the NG for "CreateTableFro mRecordset".

          Comment

          Working...