Simple Syntax Problem... I Think

Laser

Registered User.
Local time
Today, 05:28
Joined
Nov 18, 2009
Messages
26
After researching various methods to open a PDF file such as Shellexecute and hyperlink I found a helpful post from Kiwiman going back to 2008 with some success. Although I can get it to run correctly if I provide the full file location and file name I cannot get it to run correctly when pulling the data from a textbox. I am trying to get this to match the OID value within a text box and then to search a given file location for the PDF starting with the number contained within the filename provided by the OID value.
The code I am using is as follows

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

MsgBox Dir("D:" & [OID] & "*") 'Returns the correct file location and filename
Call OpenDocument("D:\12078 My Test.pdf") 'Opens the pdf document correctly
Call OpenDocument(Dir("D:" & [OID] & "*")) 'Will NOT open pdf document and does not return an error

Any help would be appreciated.
 
Last edited:
You are missing a backslash

Code:
MsgBox Dir("D\:" & [OID] & "*") 'Returns the correct file location and filename
Call OpenDocument("D:\12078 My Test.pdf") 'Opens the pdf document correctly
Call OpenDocument(Dir("D:[COLOR="Red"]\[/COLOR]" & [OID] & "*")) 'Will NOT open pdf document and does not return an error
 
Thanks Minty for responding... I am aware of the missing backslashes but the post seems to strip them out although they are there in the code on the form - Tried a couple of times to edit the post but it just removes the back slashes when posted
 
If you use the code tags, you shouldn't have that problem.
Click the # button to use them
 
If you use the code tags, you shouldn't have that problem.
Click the # button to use them

Is this button located within the database design or are you referring to the keyboard? I have only ever used the # for surrounding dates.
 
Is this button located within the database design or are you referring to the keyboard? I have only ever used the # for surrounding dates.

I meant the # button above the window where you type your post on the forum
 
Ah... I see, had me going there for a bit... Just spent some time googling for code tags for ms access Lol
 
I'm not sure why FollowHyperlink (one line of code) didn't work for you. That method works for any file time that is registered with Windows. So, you use the same instruction for .xlsx, docx, pdf, gif, AND web pages. The app doesn't need to distinguish and handle each type differently.
 
FollowHyperlink did work ok for me Pat, but security warnings keep popping up and from what I have read you have to set trusted locations in order for it to work - I don't want the end user to have to delve into the database to have to do that. I had a similar problem trying to use outlook to send emails... In the end I had to use CDO to send mail.
 
Interesting. I've never had the problem on any of my computers nor for most of my users but ONE does. It must be some OS setting.
 

Users who are viewing this thread

Back
Top Bottom