View Full Version : Opening an attachment from a form button


honeyshape
05-22-2009, 07:25 AM
Ok, so I can use the macro builder to make a button open another form, or report, but....

How do I open an attachment that is in a table. The attachment is a pdf, .docx or .xlsx file.

Kiwiman
05-22-2009, 07:31 AM
Howzit

I picked this up somewhere along the way. Can't remember where or from who to give the kudos to.

File name (full path) held in a text box (Attach1), and a command button to open the document.

Code in the form

Private Sub cmdView1_Click()
Call OpenDocument(Me.Attach1)

End Sub



In a module...

Public Sub OpenDocument(DocPath As String)
Dim A As Long
A = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocPath, vbMaximizedFocus)
End Sub


I have never tried this on Office 2007 documents, but it works on Office2003 and pdfs etc

honeyshape
05-22-2009, 08:18 AM
Thanks Kiwiman,

I will try this out after the weekend.