index > Visual Basic for Applications (VBA) > Call Windows API to store hyperlink path to external documents

Call Windows API to store hyperlink path to external documents


Hi there, this is a toughie!

I am in the process of building a new system using access and VBA. One of the major requests from users in terms of functionality for the new database is they would like the ability to store word documents, excel documents, PDF documents, scanned documents e.g. gif, tif, bmp etc against either a company or a contact within the database. I do not want to bloat the size of the database because initially it will be an Access back end. I would like to create a documents table and link it to the company table and on the company form i will then have a command button that will open up a documents form relevant to that company. On that form i would then like to be able to press a command button that will call the windows API, allow me to select the document and then store the path to that document in the documents table along with the name of the document. The documents table will then reside as a subform on the company form and i would like users to be able to see the document they have stored on the sub form and double click the document, at which time it will trace the path to the document and open it.

Ideally i would like to be able to save multiple documents to a single company in this way.

Thanks for your help, it is always much appreciated.

Rhys.

RhysDavies

Rhys no problem,

Your looking for a file open dialog to select the file for storing in the database, and for displaying the file there is a Windows API call you can use thats like a double click in explorer.

The file open dialog... this code doesn't take into consideration the user pressing cancel.

Public Sub FileOpen()

Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)

'the file open can work with multiple file selections or with single file selections
With dlgOpen
.AllowMultiSelect = False
.Show
End With

'with both singular and multiple selections you have an array
'with singular selections there is only ever one item in the array
MsgBox dlgOpen.SelectedItems(1)

End Sub

To open any file in it's registered program copy the code below into a module and from anywhere in your code call OpenFile passing in the full path to the file you want to open. PDF's will open in Acrobat, Doc's in Word, and so on.

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Sub OpenFile(file As String)
On Error GoTo OpenFile_Err
'open the document in whatever application it requires
ShellExecute 0, "open", file, vbNullString, vbNullString, vbNormalFocus
Exit Sub
OpenFile_Err:
MsgBox "An unexpected error has occurred.", vbOKOnly + vbCritical, "Error Conditon in Opening File"
End Sub




www.dsmyth.net/blog
Derek Smyth

Hi Derek, where do i enter the 'fileopen' code? I would like to enter it on the on click event of a command button?

Thanks,

Rhys.

RhysDavies

Rhys,

Create a module and copy the code I posted into it. Then in your command button OnClick event call FileOpen() passing in the full path to the file, i.e. FileOpen("C:\Images\NakedLady.jpg"). The file will open in whatever application the file type is registered too. You can pass any string as long as it's a valid path to a file that exists on the file system.




www.dsmyth.net/blog
Derek Smyth

cheers Derek, got it all working now.

Thanks again!

Rhys.

RhysDavies
reply 5

You can use google to search for other answers

 

More Articles

• Help with DDEPoke
• Selection of only one object
• Problem about the "Find" function in VBA editor
• API Used in VBA
• Access "ldb"
• Just curious (an Excel VBA question)
• SendKeys from Excel
• Getting Images embedded in Word
• Using of APC.IDE.PreventShow property
• Working with Outlook Public Folders from Excel
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• VSTA support
• adding a routine/event to a control duri
• Problems when accessing a text file usin
• Excel shape classname in Windows API
• Vb migration to Access 2003
• Passing new parameters to Report(.rdlc)
• desktop path for any given user running
• Administration tool
• Execute String as code VBA
• Novice VBA User needs help with using da
• Controlling a Word Mail Merge with Excel
• How to extract/view/capture module/forms
• Vba commands used to connect to sql
• Microsoft Access Runtime/Developer (XP)
• Run Time Error 216 at <Memory Address

Hot Articles

• handling volume control in C#
• Acces1 1.0 converted to Acces 2003 but t
• Problem regarding VBA in excel - Combine
• variable declarations
• Solved - Help with Excel VBA Code
• ActiveX Control Problem
• Problem with VBA script
• Assign Minimum and maximum values for a
• Selection of only one object
• Search all text objects - PowerPoint VBA
• Runtime error '-2147467259(80004005)';
• Copying email contents into Excel Spread
• VBA Form in MS Word template to populate
• Can no longer enter wscript for debug
• start Access Query Designer/Builder from

Recommend Articles

• Positioning DialogSheets
• Need VBA Code Help
• How do I create and use 3D ranges in Exc
• create command button that holds a proce
• Question about ADO and Access
• List Box Search
• VBA SourceName method
• File Protection from Users
• need help for VBA code(MS Access)
• Limit Macro to current workbook
• SaveAs question
• ScrollBars for Userforms
• Get the name of an user in active direct
• Excel edit mode
• Access Form "INSERT INTO" not