Using attached document as source for Bound Object Frame (1 Viewer)

pk2317

New member
Local time
Today, 10:19
Joined
Oct 15, 2010
Messages
4
A related question to my earlier one:

Is it possible to use a Bound Object Frame to display a Word document (or other OLE Object) that has been attached to a table? Here's the website I got my code from:

http://blogs.msdn.com/b/access/arch...-in-the-new-access-2007-attachment-field.aspx

I modified the code some, shown below. I have the public function first, and then the test function that is called when a command button is clicked. At this time I'm just using a small table (tblFiles) with an attachment field (Fil_File) that containts a single Word document attachment. I want it to display in the field [OLEBound7] on the form [frmDisplay].

Code:
Public Function OpenFirstAttachment(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String) As DAO.Field
 
    Dim rstChild As DAO.Recordset2
    Dim fldAttach As DAO.Field2
    Dim strFilePath As String
 
    Set rstChild = rstCurrent.Fields(strFieldName).Value ' the .Value for a complex field returns the underlying recordset.
 
    Set fldAttach = rstChild.Fields("FileData") ' The binary data of the file.
 
    Set OpenFirstAttachment = fldAttach
 
    rstChild.Close ' cleanup
 
End Function 'OpenFirstAttachment
Code:
Public Function TestFirst()
 
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim fldTemp As DAO.Field
 
    Const strTable = "tblFiles"         ' Table that contains attachment field
    Const strField = "Fil_File"         ' Attachment field in Table1
 
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset(strTable)
 
    'rst.MoveNext                       ' Uncomment this line to go to the 2nd row in the Table.
 
    Set fldTemp = OpenFirstAttachment(rst, strField)
 
    Forms![frmDisplay]![OLEBound7].ControlSource = fldTemp
 
    rst.Close
    Set dbs = Nothing
    Set rst = Nothing
 
End Function
 

Users who are viewing this thread

Top Bottom