Results 1 to 5 of 5
  1. #1
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74

    How to attach PDF file to an Access database

    Hi;


    I would like to know if there is a way to attach a PDF file to a table and call it with a button on a form. We can use it as an attachment but when clicking on this button it brings up a dialog box where you have to select the PDF file. Can we get rid of these two or three unnecessary steps, and when clicking the button, open the file straightaway?
    Thanks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    PDF can be embedded in table attachment type field. Saving files, especially image files, in db will cause the db file to grow quickly. Access has a 2GB size limit.

    Viewing that embedded file can be tricky. Review http://forums.devarticles.com/micros...ba-444117.html

    I think it is now possible to view PDF file in a WebBrowser control https://www.accessforums.net/access/...ive-41691.html
    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
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    Quote Originally Posted by June7 View Post
    PDF can be embedded in table attachment type field. Saving files, especially image files, in db will cause the db file to grow quickly. Access has a 2GB size limit.

    Viewing that embedded file can be tricky. Review http://forums.devarticles.com/micros...ba-444117.html

    I think it is now possible to view PDF file in a WebBrowser control https://www.accessforums.net/access/...ive-41691.html
    Thanks. I'll post back after trying it.

  4. #4
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    I am sorry to say that I cuuldn't get it to work.
    But I found this on another post and it worked:

    Private Sub ID_CLICK()
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Const strTable = "Table1" '<- Replace this with your table with attachment
    Const strField = "Files" '<- Replace this with the fieldname of your attachment
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("SELECT * FROM Table1 WHERE ID=" & Me.ID)
    'rst.MoveNext ' Uncomment this line to go to the 2nd row in the Table.
    OpenFirstAttachmentAsTempFile rst, strField
    rst.Close
    End Sub

    Public Function OpenFirstAttachmentAsTempFile(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String) As String
    Dim rstChild As DAO.Recordset2
    Dim fldAttach As DAO.Field2
    Dim strFilePath As String
    Dim strTempDir As String
    strTempDir = Environ("Temp") ' Get the Temp directory from the environment variable.
    If Right(strTempDir, 1) <> "\" Then strTempDir = strTempDir & "\" ' Make sure the path always ends with a backslash.
    Set rstChild = rstCurrent.Fields(strFieldName).Value ' the .Value for a complex field returns the underlying recordset.
    strFilePath = strTempDir & rstChild.Fields("FileName").Value ' 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.Fields("FileData") ' The binary data of the file.
    fldAttach.SaveToFile strFilePath
    rstChild.Close ' cleanup
    VBA.Shell "Explorer.exe " & Chr(34) & strFilePath & Chr(34), vbNormalFocus ' Use Windows Explorer to launch the file.
    End Function 'OpenFirstAttachmentAsTempFile

    But the problem is, it opens the files ina web browser. How can I get it to open the files in their default files handler? All these files are in PDF format, so I want them to open in Adobe reader. Can we do this?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    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.

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

Similar Threads

  1. Attach Database to Email
    By SSgtBarry in forum Access
    Replies: 2
    Last Post: 08-10-2014, 08:42 PM
  2. Access: Attach to a folder
    By HelpMeWithAccess in forum Access
    Replies: 5
    Last Post: 07-02-2014, 08:11 AM
  3. please use linked table manager to properly attach database
    By Chris Acker in forum Database Design
    Replies: 2
    Last Post: 10-23-2013, 09:16 AM
  4. attach scanner to access
    By msasan1367 in forum Access
    Replies: 3
    Last Post: 03-14-2013, 10:52 AM
  5. How do you bulk attach files in Access?
    By newyorkyankee in forum Access
    Replies: 5
    Last Post: 05-11-2012, 01:06 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