Unanswered: Linking to an arbitrary document, browsing for and storing it
I would like a table to have a field linked to a document outside of the database. I would like the form associated with the table tohave a button that can browse and pick the file to store/link, and another button to actually open the document with whatever program is associated with it. Can anyone help me to do this?
This is an automation and API question and a half. Luckily the API part is encapsulated in, I think, the scripting object or DLL. I know I've done it before but can't remember the details.
I believe what your asking is some way of browsing the Windows directories to locate a document. This is where the scripting comes in. Then according to the file name extension determine which application to automate. This is a registry lookup. Then open that application (automation) and get it to display the document. I don't know of any way to fire up the application directly from the file name in a similar manner to double-clicking on it when you are in Explorer. I imagine there may be an API for this but whoa! Again can one use hyperlinks?
I suppose the question is how familiar are you with all of the above techniques? Is there another way of doing this?
So how do I open a browse window to pick the file and same the link?
I believe you need to use Common Dialog Control to pick a file. I don't know how to do it though. control should be somewhere in extra ActiveX control list.
to execute a document create a module and copy following code that I found into it:
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
Declare Function GetForegroundWindow Lib "user32" () As Long
Sub ShellEx(FileName As String)
ShellExecute GetForegroundWindow, "Open", FileName, "", "", 1
then you can open any file with Shellex(filenamehere). example:
One snag: the Common Dialog Control, cmdlg32.ocx if memory serves, is a VB control and is not supplied with VBA (Office). If you haven't bought VB then you will have to beg, borrow or steal it and I'm not sure where that leaves you legally vis-a-vis Microsoft.
Other options are to have a look at the DIR function and see whether you can use that - tedious though it will prove to be - or investigate the Scripting Runtime library for useful functions.
Hmm! I thought it would be a good idea if I also had this control. Now there seems to be confusion whether it's called cmdlg32.ocx or comdlg32.ocx. I found a copy of the latter, downloaded it and installed it.
When I tried to use it however I got the 'You don't have a licence ... ' message. It seems Microsoft has the copyright angle covered.
Rod, to be honest I never tried it before. it is in my list of activex controls even I don't have Visual Basic. But you are right, it asks for licence if you try to use it. but here is a link tells how to do it without common dialog control. http://www.developerfusion.com/show/2127/