Attaching a file to a record (1 Viewer)

Ildanach

New member
Local time
Today, 15:11
Joined
Jul 23, 2008
Messages
5
Hello one and all,

First off just let me state my level expertise with Access......that is to say I have none LOL. I am a complete newbie when it comes down to it. I am diving in at the deep end and working on 3 databases for work. I will admit that I do know the very very basics...I can create table and forms and have them work to add data to the tables but that is about it :)

As I said diving well and truly in at the deep end so I am hoping a few people here will be kind enough to help me out. And I will also apologise straight up if I get the terminology wrong.....from past experiences....not knowing the right terminology can be a huge hinderance in searching for help....but I will try my best.

Ok so here is my first question;

Is it possible to attach a file to a record through a button on a form? The file in question will most likely be a PDF, DOC or EXCEL file.

Ideally I would like the file actually "attached" to the the record and stored in the same location as the database, if this is not possible I would like the form to contain a button so that upon review of the record in question a user can click "View file" button and it will open the required file.

Any help tips or suggestions would be greatly appreciated.

Thanks a million in adavance!

David

PS: If any more info is required please just shout and I will provide what I can.
 

Steve R.

Retired
Local time
Today, 01:11
Joined
Jul 5, 2006
Messages
4,705
The answer is yes, but it is not that simple. In short the recommended approach is to link to the file in question. You can embed a document file into an ACCESS record, but it is not recommended as it consums a lot of space.

I am using ACCESS 2000 and I have limited experience in linking. The newer versions of ACCESSS may make linking easier. The code below is a sample of how to open a Word document. I don't have one for a PDF file.

Code:
Private Sub Command349_Click()
    Rem VERSION #1
    Rem This version requires that "Microsoft Word 9.0 Object Library" be checked in references.
    Dim strPath As String
    Dim bolTrue As Boolean
    Dim WordApp As Word.Application
    Dim WordDoc As Word.Document
    bolTrue = False
    Select Case Me.typenum
        Case 1 'Part "C"
        Case 2  'Part "D"
        Case 3  'Part "E"
        Case 4  'Part "F"
            strPath = "P:\Federal Consistency\Databases\HelpFiles\FederalAssistance.doc"
            bolTrue = True
        Case 5  'State Clearinghouse
            strPath = "P:\Federal Consistency\Databases\HelpFiles\StateClearinghouse.doc"
            bolTrue = True
        Case 6  'Other Environmental Review
        Case Else
    End Select
    If bolTrue Then
        Set WordApp = New Word.Application
        Set WordDoc = WordApp.Documents.Open(strPath)
        WordApp.Visible = True
        End If

    Rem VERSION #2
    Rem does not open in full window.
    Rem Note the use of quotation marks to get over the space between the words "Federal Consistency". Recommend single words, of course.
    Rem Dim RetVal As Integer
    Rem Dim strPath As String
    Rem retVal = Shell("WINWORD.EXE " & """P:\Federal Consistency\Databases\FederalAssistance""", vbMaximizedFocus)

End Sub

Please see the response by Kiwiman here. I have not tried it, but it is a more universal approach.
 
Last edited:

Users who are viewing this thread

Top Bottom