How To Format Data Sent To Word?

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

    How To Format Data Sent To Word?

    I am using "acCmdOutputToR TF" to send the results of a query to Word.
    This works well, but the user then has to change the page layout of
    the Word document to "landscape" and use the Word "autofit to window"
    menu item to make all columns visible because they "run off" the right
    hand side of the page.

    Is there any way to automate the Word formatting from Access?
  • Tom van Stiphout

    #2
    Re: How To Format Data Sent To Word?

    On Thu, 2 Oct 2008 15:12:17 -0700 (PDT), Wayne
    <cqdigital@volc anomail.comwrot e:

    Yes. It's called Automation.
    Tip: record a macro in Word to do these things like switch to
    Landscape and see what kind of VBA that outputs. This will be the
    basis for your code as well.
    Tip: the VBA help file only gets installed with a full installation of
    Office, not with a typical one.
    It all starts with CreateObject("W ord.Application "). I'm sure Google
    has a ton of links.

    -Tom.
    Microsoft Access MVP

    >I am using "acCmdOutputToR TF" to send the results of a query to Word.
    >This works well, but the user then has to change the page layout of
    >the Word document to "landscape" and use the Word "autofit to window"
    >menu item to make all columns visible because they "run off" the right
    >hand side of the page.
    >
    >Is there any way to automate the Word formatting from Access?

    Comment

    • Wayne

      #3
      Re: How To Format Data Sent To Word?

      On Oct 3, 12:54 pm, Tom van Stiphout <tom7744.no.s.. .@cox.netwrote:
      Yes. It's called Automation.
      Tip: record a macro in Word to do these things like switch to
      Landscape and see what kind of VBA that outputs. This will be the
      basis for your code as well.
      Tip: the VBA help file only gets installed with a full installation of
      Office, not with a typical one.
      It all starts with CreateObject("W ord.Application "). I'm sure Google
      has a ton of links.
      >
      -Tom.
      Microsoft Access MVP
      >
      Thanks for the heads up Tom. I know that this is rough and that there
      will be a million better ways to do this, but the code below is what I
      have come up with. It achieves the desired result. The only slight
      annoyance is that the first row of the Word table contains the Access
      query name, but I can live with that.

      On Error Resume Next
      DoCmd.Echo False
      DoCmd.SetWarnin gs False
      DoCmd.OpenQuery "Query_By_Form_ Output"
      DoCmd.RunComman d acCmdSelectAllR ecords
      DoCmd.RunComman d acCmdCopy
      DoCmd.Close acQuery, "Query_By_Form_ Output"

      Dim oWord As Word.Applicatio n
      Set oWord = CreateObject("W ord.Application ")
      oWord.Visible = True
      oWord.Documents .Add
      oWord.Selection .PageSetup.Orie ntation = wdOrientLandsca pe
      oWord.Selection .Paste
      DoCmd.Echo True
      DoCmd.SetWarnin gs True

      Comment

      Working...