?
Solved

FollowHyperlink on Access Form

Posted on 2009-02-24
20
Medium Priority
?
798 Views
Last Modified: 2013-11-28
I have an Access form with a button on it and shared drive with a directory containing .pdf's. On the form I have a field named MLCAT that is the primary key. The MLCAT for a given record matches the corresponding PDF in the shared directory. When I click my "Get PDF" button I want it to open the corresponding PDF. Here's the code I have so far:

Private Sub getPDF_Click()
Const cstrDrawings = "F:\Customer Drawings\"

On Error Resume Next
   
    FollowHyperlink cstrPicsFolder & mlcat
End Sub

When I click the button it looks at the MLCAT field and pulls the name but it doesn't open the PDF with the matching name. How can I get this to work? Thanks.
Private Sub getPDF_Click()
Const cstrDrawings = "F:\Customer Drawings\"
 
On Error Resume Next
    
    FollowHyperlink cstrPicsFolder & mlcat
End Sub

Open in new window

0
Comment
Question by:Haze0830
  • 7
  • 7
  • 6
20 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23723329

Private Sub getPDF_Click()
Const cstrDrawings = "F:\Customer Drawings\"
 
On Error Resume Next
   
'add this line remove later

      msgbox  cstrPicsFolder & mlcat


    FollowHyperlink cstrPicsFolder & mlcat
End Sub

see if you have the correct format of the string path from the message box


0
 
LVL 61

Expert Comment

by:mbizup
ID: 23723342
It doesn't look like you have defined cstrPicsFolder.

Should your code be this?

Private Sub getPDF_Click()
Const cstrDrawings = "F:\Customer Drawings\"
 
On Error Resume Next
   
    FollowHyperlink cstrDrawings & mlcat
End Sub
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23723398
i assumed it was defined somewhere, a global variable or declared at the top of the module
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 61

Expert Comment

by:mbizup
ID: 23723416
If that does not work, temporarily document out the On Error Resume Next line.

That will allow the code to fail with an error number and message that you can post back in this thread.

These details will make it easier for us to help you.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 23723435
<a global variable or declared at the top of the module>

It very well could be... those details would be good to know too.  :-)
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23723470
that is why i suggested the msgbox...
0
 
LVL 2

Author Comment

by:Haze0830
ID: 23723504
Well I identified the obvious problem in that my const is cstrDrawings and my code calls cstrPicsFolder.

I fixed that and added your line of code and get F:\Customer Drawings\MLCAT - so it's hitting the right directory....still not working though.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23723532
this

F:\Customer Drawings\MLCAT

does not state the file name that you want to open

should be

F:\Customer Drawings\MLCAT\myPdf.pdf
0
 
LVL 2

Author Comment

by:Haze0830
ID: 23723553
It throws the error  "cannot open the specified file" Runtime Error 490
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23723585
Haze0830,

there is no way for us to understand the error you are posting if you will not include what you did with the codes...

0
 
LVL 2

Author Comment

by:Haze0830
ID: 23723589
Capricorn,

It looks at another field to pull the file name - FollowHyperlink cstrDrawings & **MLCAT** where MLCAT equals the file name I want.
0
 
LVL 2

Author Comment

by:Haze0830
ID: 23723630
I cutout the On Error line as mbizup suggested....

The code in it's entirety at this given moment is the following:

Private getPDF_Click()
Const cstrDrawings = "F:\Customer Drawings\"
   
MsgBox cstrDrawings & mlcat

    FollowHyperlink cstrDrawings & mlcat

End Sub



0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 23723692
the reason why you are getting the error is
you did not specify the name of the file you want to open.

can you post the complete Path to the file

0
 
LVL 2

Author Comment

by:Haze0830
ID: 23723797
I'll repost this again -

Capricorn,

It looks at another field to pull the file name - FollowHyperlink cstrDrawings & **MLCAT** where MLCAT equals the file name I want.


So to recap - MLCAT is a field on my form that CONTAINS the file name. The complete path is F:\Customer Drawings\MLCAT

...where MLCAT *equals* the filename........

So if the value in MLCAT is EXAMPLE001 then the string (ie PATH) is compiled as F:\Customer Drawings\EXAMPLE001 which is the correct path and which is exactly what the code is doing.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 total points
ID: 23723886
still this

F:\Customer Drawings\EXAMPLE001

will not be recognized as a complete file path,  there is no extension

maybe you could do this

FollowHyperlink cstrDrawings & MLCAT & ".pdf"

if the file extension is .pdf
0
 
LVL 61

Expert Comment

by:mbizup
ID: 23723899
Do you need to add the .PDF extension?

Also check file permissions...
0
 
LVL 2

Author Comment

by:Haze0830
ID: 23724012
Yeah, that did the trick. It irritates me that I've used this code 100 times with no extension and it has worked fine.

Thanks!
0
 
LVL 61

Expert Comment

by:mbizup
ID: 23725901
Haze0830,

You remarked that my comment about using the incorrect constant was "obvious".  
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24172588.html#23723342

However it was just as critical to fixing your code as the filename extension was.
0
 
LVL 2

Author Comment

by:Haze0830
ID: 23726729
I hadn't seen your comment prior to me discovering and resolving that issue on my own. Sorry.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 23726904
<prior to me discovering and resolving that issue on my own>
No problem, and I'm not going to request a points split, but please keep in mind in future questions that we only have the information that you present to go on.  Your questions should be closed according to what resolves your post as originally stated, even if you do make discoveries outside of what is posted the question.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question