Results 1 to 3 of 3
  1. #1
    air3jxt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    New Albany, IN
    Posts
    4

    Print an embedded Word document

    Hey guys!

    I have an Access 2010 database that I have handed off to another department to use. I have written a "How To" document for them. Currently the database allows them to define a path to its documents, etc., and as long as the How To doc is in that folder it will print. However, I do not want to have to rely on them to move the document should they move the database or change the path. So, I have created a table called EMBEDDED and it has one Attachment field called DOCUMENT. The only data in it is this How To document and I'm really struggling finding anything about how to print it. Can anyone help?



    Thanks,
    Jay.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    The only way I know to do this is to save the embedded document out to an external folder. Review http://blogs.office.com/b/microsoft-...ent-field.aspx

    Instead of the line calling Windows Explorer to open the document, use code that creates a Word object and manipulate the object. Here is one example:
    http://answers.microsoft.com/en-us/o...1-c317123b29ce

    This code worked for me:
    Code:
    Public Sub TestOpenFirstAttachmentAsTempFile()
        Dim rst As DAO.Recordset
        Dim rstChild As DAO.Recordset2
        Dim fldAttach As DAO.Field2
        Dim strFilePath As String
        Dim strTempDir As String
        Set rst = CurrentDb.OpenRecordset("SELECT Document FROM Airports WHERE FAAID='6K8';")
        strTempDir = CurrentProject.Path
        If Right(strTempDir, 1) <> "\" Then strTempDir = strTempDir & "\" ' Make sure the path always ends with a backslash.
            Set rstChild = rst!Document.Value ' the .Value for a complex field returns the underlying recordset.
            strFilePath = strTempDir & rstChild!FileName ' Append the name of the first (and only) attached file to temp dir.
            If Dir(strFilePath) <> "" Then ' the file already exists--delete it first.
            VBA.SetAttr strFilePath, vbNormal ' remove any file attributes (e.g. read-only) that would block the kill command.
            VBA.Kill strFilePath ' delete the file.
        End If
        Set fldAttach = rstChild!FileData ' The binary data of the file.
        fldAttach.SaveToFile strFilePath
        rstChild.Close ' cleanup
        With CreateObject("Word.Application")
            With .Documents.Open(strFilePath)
                .PrintOut
                .Close False
            End With
            .Quit
        End With
        Kill strFilePath
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    air3jxt is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2013
    Location
    New Albany, IN
    Posts
    4
    That did the trick - thanks for the help!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code to print 'section' of a word document.
    By TurnipGrnPeace in forum Access
    Replies: 6
    Last Post: 06-25-2013, 07:17 PM
  2. Create new Word document.
    By Bill H in forum Programming
    Replies: 3
    Last Post: 06-12-2012, 06:40 AM
  3. Export report to word document
    By jackyoung2012 in forum Reports
    Replies: 1
    Last Post: 03-16-2012, 11:16 AM
  4. Import Word document using VBA
    By degras in forum Import/Export Data
    Replies: 4
    Last Post: 04-12-2011, 02:40 AM
  5. Open a word document from access
    By natalia in forum Programming
    Replies: 1
    Last Post: 10-13-2010, 08:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums