Power Query Course in Spanish
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Export report to Word document

  1. #1
    Board Regular
    Join Date
    May 2015
    Location
    Central Queensland
    Posts
    206
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Export report to Word document

    Hello and thank you for any attention my post may receive.

    I have a report in my Access db which I would like to export as a DOC or RTF so that images can be pasted to it, rather than import the images in the db which will take up too much room.

    I can successfully export the report as both DOC and RTF which is fine however ideally the document fields and formatting need to be protected, except for the two fields where an image will be pasted. Is this possible? Or is there another file format which will achieve my goal. Or is there another solution such as exporting to a template document?

    I would also like to save the document to the user's desktop and open upon export.

    Thank you and have a great day!
    Cheers and have a great day,
    Nadine

    Office2016 on Windows 8

  2. #2
    Board Regular
    Join Date
    Jun 2015
    Location
    Ontario, Canada
    Posts
    1,511
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    Have to confess I've never put an image control on a report, but I suspect it could load the correct image based on a (hidden) textbox that contained the image path for a given record, assuming you're talking about several images related to records. If you're not, and the images have nothing to do with records or no more than one record, that would be easier. Then you export the report as a pdf - no concerns about protection. Saving it to a desktop and causing it to open is definitely all code, and can be a bit problematic what with security issues. Could be done methinks, but there are other ways you might want to deal with it, such as sending the pdf by email instead.
    Tips for posting problems:
    1) "doesn't work" doesn't help. Post error message text/numbers and/or state what's happening.
    2) if posting code or sql, use code tags; specify on which code line errors occur, if applicable
    3) try to be specific; assume we know nothing about your issue - because we don't!

    Make all suggested changes in copies of your database or to its objects.

    "1 out of 1010 people understand binary. The other 1001 don't."

  3. #3
    Board Regular
    Join Date
    May 2015
    Location
    Central Queensland
    Posts
    206
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    Micron thank you for your reply.

    I am starting to think I need a Word doc on the server which is opened and populated from within Access.

    I need to make the whole process rather basic for the end-user and so my way of thinking is changing now. I think it might be possible to open a word doc and populate it with the current data and then the user can paste the two images to the relevant fields. My challenge is to come up with the code to enable this..........

    Any suggestions as to the code to do this will be greatly appreciated.

    Have a great day!
    Cheers and have a great day,
    Nadine

    Office2016 on Windows 8

  4. #4
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,674
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    With the doc format, if you add Section breaks either side of where the images are to go and apply 'filling in forms' protection to the document, leaving the Sections where the images are to go unprotected, you can insert the images there. With the docx format, you could do something similar without the need for Section breaks, by applying Word's 'read only (no changes)' protection to the document, marking the locations where the images are to go as exceptions. Of course, if you apply whatever protection you choose to the whole document after adding the images, the issue doesn't arise.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  5. #5
    Board Regular
    Join Date
    May 2015
    Location
    Central Queensland
    Posts
    206
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    Thank you Macropod.

    Ok so this is the code I currently have to open the Word docx (which has certain fields protected). How do I get the protected fields to populate with the data which I have entered on my MS Access form (frmEnter)?

    Code:
    Private Sub Command34_Click()
    Application.FollowHyperlink "S:\14.BEX\STRATEGIC IMPROVEMENT PROCESS\Forms\Strategic Improvement Idea Capture Form - 20160401.docx"
    End Sub
    Last edited by Nadine67; Apr 18th, 2018 at 08:26 PM.
    Cheers and have a great day,
    Nadine

    Office2016 on Windows 8

  6. #6
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,674
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    Personally, I'd use some fairly standard Word automation code instead of Application.FollowHyperlink. There's plenty of that about for populating formfields, content controls, bookmarks, tables, and mergefields - just choose whatever is appropriate for your situation.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  7. #7
    Board Regular
    Join Date
    May 2015
    Location
    Central Queensland
    Posts
    206
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    Quote Originally Posted by Macropod View Post
    Personally, I'd use some fairly standard Word automation code instead of Application.FollowHyperlink. There's plenty of that about for populating formfields, content controls, bookmarks, tables, and mergefields - just choose whatever is appropriate for your situation.
    Paul I am not sure of how to enable Word automation. I know how to 'bookmark' fields on my Word docx and that is about it.
    Cheers and have a great day,
    Nadine

    Office2016 on Windows 8

  8. #8
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,674
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    Quote Originally Posted by Nadine67 View Post
    I know how to 'bookmark' fields on my Word docx and that is about it.
    Your terminology seems loose. One doesn't ordinarily bookmark fields in Word. One might bookmark a range or insert a formfield (which typically has an internal bookmark name), but one doesn't ordinarily insert a field of some kind then bookmark it. Perhaps you could clarify.

    Basic code for Word automation:
    Code:
    Sub Demo()
    'Note: A reference to the Word library must be set, via Tools|References
    Dim wdApp As New Word.Application, wdDoc As Word.Document, StrName As String
    Const TmpltNm As String = "S:\14.BEX\STRATEGIC IMPROVEMENT PROCESS\Forms\Strategic Improvement Idea Capture Form.dotx"
    If Dir(TmpltNm) = "" Then Exit Sub
    StrName = Split(TmpltNm, ".dotx")(0) & " - " & Format(Now, "YYYYMMDD")
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Add(Template:=TmpltNm, Visible:=True)
    With wdDoc
      'update the document
      
      'save & close
      .SaveAs Filename:=StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
      ' and/or:
      .SaveAs Filename:=StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
      .Close SaveChanges:=True
    End With
    Set wdDoc = Nothing: Set wdApp = Nothing
    End Sub
    Note that the code assumes you're creating a new document from a Word template. As coded, the above sub assumes you're saving the document back to the same folder as that template and adding the current date to the filename.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  9. #9
    Board Regular
    Join Date
    May 2015
    Location
    Central Queensland
    Posts
    206
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    Thank you so much Paul.

    So your code goes in the word template document or is in the form control of the .accdb?

    I do apologise for my confusion.
    Cheers and have a great day,
    Nadine

    Office2016 on Windows 8

  10. #10
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,674
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Export report to Word document

    The code would go in a VBA module in your Access database.
    Cheers
    Paul Edstein
    [MS MVP - Word]

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

DMCA.com