Click and open a file (I'm sure it's elementary)

nst

Registered User.
Local time
Today, 10:32
Joined
Jul 31, 2005
Messages
38
I have created a database where I store my ebooks.
Therefore, let's assume that in the field "Title" there is an entry called "cooking.pdf". The file is physically stored, let's say at C:\MyEbooks\cooking.pdf
I created a query where I get the records of the table (all or filtered) and I added a field where I wrote 'Link to Open: "C:\MyEbooks\"+[title] where title is the name of the field in the table, where the filename is stored.

Then I created a Form which represents the query's fields. On the properties of that last field I changed at the bottom the Boolean parameter 'Is Hyperlink' to Yes.

I assumed that by clicking on that field I will have the book opened automatically for me. Alas, it doesn't work...

I guess, it needs some piece of code, maybe in Visual Basic, which is the lang that Office is using. It's not my strenght though...

Any ideas on how to achieve this (maybe a button with a code)
 
Easy way (other ways are there):
Create a button call it HLink.
Paste this in the Click Event:
Private Sub hlink_Click()
hlink.HyperlinkAddress = Link.Value
End Sub

Where Link is the Textbox in which you store the returned value from the query(your C:\MyEbooks\....)
When you click the button it will open the link in the textbox.
hth
Chris
 
Searching this forum is such a novel idea. :p

Pay attention to the ShellExecute method I am using to open a file in my
Browse [Find a directory or file] sample.
 
Easy way (other ways are there):
Create a button call it HLink.
Paste this in the Click Event:
Private Sub hlink_Click()
hlink.HyperlinkAddress = Link.Value
End Sub

Where Link is the Textbox in which you store the returned value from the query(your C:\MyEbooks\....)
When you click the button it will open the link in the textbox.
hth
Chris

Yes! It worked (...half). Thank you.

It opens chm files but not pdf files...

Here are some more details:

I'm using Acrobat 7 and Access 2003.
If the file is a pdf, acrobat will execute and then close instantly. If an instance of the programm is running it will not load the file.
OS is WinXP SP2
 
The fScanDirSelectFileFromTable form in the link I provided above will show you how to open a file with the click of a button using the ShellExecute method. The ShellExecute method will not fail because of a long directory name or if the file name or the path name contains a space.
 
ghudson: It seems to be my case. Thanks.

Using dopedealer's way it worked as in the following:

Code:
Private Sub Hlink_Click()
HLink.HyperlinkAddress = LinkToOpen.Value
End Sub
where LinkToOpen is the field containing the Path.

How should this be changed according to your way?

I changed it into

Code:
Private Sub Hlink_Click()
 OpenFile LinkToOpen.Value
End Sub
but didn't work.
 
Did you import [or copy] the dOpenFile module from my sample into your db.

The correct way to call the OpenFile() function would be...

Code:
OpenFile(LinkToOpen)
 
ghudson said:
Did you import [or copy] the dOpenFile module from my sample into your db.

The correct way to call the OpenFile() function would be...

Code:
OpenFile(LinkToOpen)

Code:
Private Sub bOpenFile_Click()
On Error GoTo Err_bOpenFile_Click

    OpenFile (LinkToOpen)

Exit_bOpenFile_Click:
    Exit Sub
    
Err_bOpenFile_Click:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_bOpenFile_Click
End Sub

I did it again naming the button bOpenFile, I run it and

Code:
Compile error:
Sub or Function not defined

Why?
 
I did it again naming the button bOpenFile, I run it and

Code:
Compile error:
Sub or Function not defined
Your error message makes me ask the question again...
Did you import [or copy] the dOpenFile module from my sample into your db.

You have to copy the code in my samples dOpenFile module into your database so that you can CALL the OpenFile() function.

AND the name of your command button must match the name of the sub in your forms module. If your button in named bOpenFile then your OnClick sub must be named bOpenFile_Click
 
It worked now. I inserted the Exported Module 'dOpenFile.bas' and everything is OK. It wasn't so elementary, after all.
Thanks for your nice help, ghudson.

Still, I wonder why the previous method has problems opening pdf files?

Anyway...
 
Last edited:

Users who are viewing this thread

Back
Top Bottom