View Full Version : how to get access 2007 attachments intp excel as file links


xtremax
01-29-2008, 03:14 PM
Hi ,
the db contains attachments and i want to retrieve these attachments as actual file links in excel 2007. the table in db contains four fiels, one of them is an attachment with "@" as field name. this field contains excel files. i want to be able to open these files from excel.

the code below only retrieves the whole table as text and not as links

'Option Explicit
Sub GetAccessData()

'Step 1: Declare your Variables
Dim MyConnect As String
Dim MyRecordset As ADODB.Recordset
Dim MySql As String

'Step 2: Declare your Connection String
MyConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=C:\Documents and Settings\alex\My Documents\Dn2.accdb"
'Step 3: Instantiate and Specify your Recordset

MySql = "SELECT * FROM _worksheets"
Set MyRecordset = New ADODB.Recordset
MyRecordset.Open MySql, MyConnect, adOpenStatic, adLockReadOnly

'Step 4: Copy the Recordset to Excel
Sheets("Your").Select
ActiveSheet.Range("A2").CopyFromRecordset MyRecordset

'Step 5: Add Column Labels
With ActiveSheet.Range("A1:d1")
.Value = Array("ID", "@", "user_id", "_month_id")
.EntireColumn.AutoFit
End With

End Sub

this runs with this output:

ID @ user_id _month_id
1 schedule1.xlsx 1 1
2 schedule1.xls 1 1
3 schedule1.xlsx 2 1
4 schedule1.xlsx 4 4
6 schedule1.xlsx 2 4

is there a way i can get the excel files out of database as actul file links.
i need to open these files in excel from db so that a report can be made.

hope i was clear enough. thanks.

xtremax
01-30-2008, 10:30 AM
anyone on the above issue. still waiting. hope someone can guide me.
regards.