Results 1 to 6 of 6
  1. #1
    manhvela is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    4

    Transfering Picture Attachment from Access to Word Document

    Hello I'm trying to do what the title says but I don't know how.

    I'm using .FormFields to transfer text and it works but I don't know how to transfer an image from an attachment field in Access to a Word Document(Maybe in a picture frame or smthing?)



    Please help

  2. #2
    manhvela is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    4
    noone???????????????????????????

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    From what I can find your only option is to save the attachment as a picture file then open that file in word.


    Sent from my iPhone using Tapatalk

  4. #4
    manhvela is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    4
    I want to do this automatically when I press a button! I need some code
    Quote Originally Posted by andy49 View Post
    From what I can find your only option is to save the attachment as a picture file then open that file in word.


    Sent from my iPhone using Tapatalk

  5. #5
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    I got this to work on mine.

    Code:
    Option Compare Database
    Private Sub openinword(graphimage As String)
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Set wrdApp = CreateObject("Word.Application")
    Dim filesave As String
    Dim objWdRange As Word.Range
    Dim shortString As String
    filesave = "C:\Users\Andy\Documents\pictureimport_test.docx" ' change as you wish
    DeleteFile (filesave)
    
    wrdApp.Visible = True
        Set wrdDoc = wrdApp.Documents.Open("C:\Users\Andy\Documents\pictureimport.docx") 'this is the word file with the bookmark Graphimage in it
        With wrdDoc
    '        If .Bookmarks.Exists("pic2") Then
    '           .Bookmarks("pic2").Range.Text = shortString
    '        End If
         If .Bookmarks.Exists("GraphImage") Then
             Dim wrdPic As Word.InlineShape
             Set wrdPic = .Bookmarks("GraphImage").Range.InlineShapes.AddPicture(filename:=graphimage, LinkToFile:=False, SaveWithDocument:=True)
             wrdPic.ScaleHeight = 50
             wrdPic.ScaleWidth = 50
         End If
           .SaveAs "C:\Users\Andy\Documents\pictureimport_test.docx"
        End With
        wrdDoc.Close
        Set wrdDoc = Nothing
        wrdApp.Quit
        Set wrdApp = Nothing
    End Sub
    
    
    Sub DeleteFile(ByVal FileToDelete As String)
       If FileExists(FileToDelete) Then 'See above
          ' First remove readonly attribute, if set
          SetAttr FileToDelete, vbNormal
          ' Then delete the file
          Kill FileToDelete
       End If
    End Sub
    
    
    Function FileExists(ByVal FileToTest As String) As Boolean
       FileExists = (Dir(FileToTest) <> "")
    End Function
    
    
    Private Sub picturesaving()
    'saves the picture in the attachment field [Picturefield] as the file picsaved.jpg
    'assumes TableName Is "tbl_pictures"
    'Field Is picturefield
    'make sure you have the microsoftword object Library reference (I had 14.0)
    Dim db As Database
    Dim rst As DAO.Recordset
    Dim rsA As DAO.Recordset
    Dim filename As String
    filename = "C:\Users\Andy\Documents\picsaved.jpg" 'change accordingly for your directory
    Set db = CurrentDb
         Set rst = db.OpenRecordset("tbl_pictures") 'replace with qrysomething if you have one
         Set rsA = rst.Fields("picturefield").Value
    DeleteFile (filename) ' check to see if the file exists and deletes it
    rsA.Fields("FileData").SaveToFile filename
    openinword (filename)
    rsA.Close
    Set rsA = Nothing
    End Sub
    Limitations - it gets one picture from the table. You may need to tweak it slightly as I'm sure you'll have more than one attachment in your table.

    But you can replace the name of a query where I have indicated

  6. #6
    manhvela is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    4
    Thanks friend I will try it
    Quote Originally Posted by andy49 View Post
    I got this to work on mine.

    Code:
    Option Compare Database
    Private Sub openinword(graphimage As String)
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Set wrdApp = CreateObject("Word.Application")
    Dim filesave As String
    Dim objWdRange As Word.Range
    Dim shortString As String
    filesave = "C:\Users\Andy\Documents\pictureimport_test.docx" ' change as you wish
    DeleteFile (filesave)
    
    wrdApp.Visible = True
        Set wrdDoc = wrdApp.Documents.Open("C:\Users\Andy\Documents\pictureimport.docx") 'this is the word file with the bookmark Graphimage in it
        With wrdDoc
    '        If .Bookmarks.Exists("pic2") Then
    '           .Bookmarks("pic2").Range.Text = shortString
    '        End If
         If .Bookmarks.Exists("GraphImage") Then
             Dim wrdPic As Word.InlineShape
             Set wrdPic = .Bookmarks("GraphImage").Range.InlineShapes.AddPicture(filename:=graphimage, LinkToFile:=False, SaveWithDocument:=True)
             wrdPic.ScaleHeight = 50
             wrdPic.ScaleWidth = 50
         End If
           .SaveAs "C:\Users\Andy\Documents\pictureimport_test.docx"
        End With
        wrdDoc.Close
        Set wrdDoc = Nothing
        wrdApp.Quit
        Set wrdApp = Nothing
    End Sub
    
    
    Sub DeleteFile(ByVal FileToDelete As String)
       If FileExists(FileToDelete) Then 'See above
          ' First remove readonly attribute, if set
          SetAttr FileToDelete, vbNormal
          ' Then delete the file
          Kill FileToDelete
       End If
    End Sub
    
    
    Function FileExists(ByVal FileToTest As String) As Boolean
       FileExists = (Dir(FileToTest) <> "")
    End Function
    
    
    Private Sub picturesaving()
    'saves the picture in the attachment field [Picturefield] as the file picsaved.jpg
    'assumes TableName Is "tbl_pictures"
    'Field Is picturefield
    'make sure you have the microsoftword object Library reference (I had 14.0)
    Dim db As Database
    Dim rst As DAO.Recordset
    Dim rsA As DAO.Recordset
    Dim filename As String
    filename = "C:\Users\Andy\Documents\picsaved.jpg" 'change accordingly for your directory
    Set db = CurrentDb
         Set rst = db.OpenRecordset("tbl_pictures") 'replace with qrysomething if you have one
         Set rsA = rst.Fields("picturefield").Value
    DeleteFile (filename) ' check to see if the file exists and deletes it
    rsA.Fields("FileData").SaveToFile filename
    openinword (filename)
    rsA.Close
    Set rsA = Nothing
    End Sub
    Limitations - it gets one picture from the table. You may need to tweak it slightly as I'm sure you'll have more than one attachment in your table.

    But you can replace the name of a query where I have indicated

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

Similar Threads

  1. Replies: 3
    Last Post: 02-11-2015, 01:29 PM
  2. Replies: 1
    Last Post: 01-24-2014, 01:21 PM
  3. Export Microsoft Query with Picture Fields to a Word Document
    By KSReynolds in forum Import/Export Data
    Replies: 2
    Last Post: 10-15-2013, 02:36 PM
  4. Replies: 1
    Last Post: 08-30-2011, 11:54 PM
  5. Word document INTO Access form
    By jonathonhicks in forum Forms
    Replies: 0
    Last Post: 04-30-2007, 05:59 PM

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