Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need VBA code to open .PDF file in different program

Status
Not open for further replies.

tammy23

Technical User
Aug 3, 2010
17
US
I am trying to write a code and am failing miserably. I have a command button in a subform...I would like to click on that button and have a .pdf file (associated with the current entry) open in a program other than Adobe Acrobat. The file paths are entered as a field in a table called tblWellLogs, the field is "FileLoc".

I get the error "can't find the field 'File Loc' referred to in your expression"...if I remove "strFile etc" the program opens fine but of course no file. Please help if you can--I also tried opening the program and then opening a hyperlink to the file using VBA and it did not work :(

Here's my code:

Dim strProg As String
Dim strFile As String

strProg = "C:\nds\bin\NeuraView.exe"
strFile = Me!FileLoc

Call Shell(strProg & " " & strFile, vbMaximizedFocus)
 
Is the field name "FileLoc" or "File Loc"?
Try strFile = Me![FileLoc] or strFile = Me![File Loc] (enter the name exactly as it appears in your DB).
 
The field name is "FileLoc" no space...and thanks for the suggestion to use [] but it didn't work....still same error.
 
In debug mode you will want to look at the value of Me![FileLoc] to see if it is what you expect.
 
It equals the error message "....can't find the field 'File Loc' referred to in your expression
 
The "Me" keyword usually refers to a form, do you have a bound control that points to the field [FileLoc]?

If so, you should be able to use something like Me.<control bound to field FileLoc>.Value.
 
It worked using the following code (see below): I had to use DLookup to query the file path from my table. The only thing I can't figure out now is I want [Well].WellLogDetails to equal the entry I am viewing and the only way I could think to do that was to open a report and pull the [Well].value from the report, so my code had to include a command to open the report...kind of shotty but it works. Now my .pdfs open in my designated program and its the file I want so...yay me! Thanks for helping.


Dim strProg As String
Dim strFile As String
Dim a As String
Dim stDocName As String

stDocName = "Report1"
DoCmd.OpenReport stDocName, acPreview

a = DLookup("[FileLoc]", "WellLogDetails", "[Well]=Reports!Report1![Well]")

strProg = "C:\nds\bin\NeuraView.exe"
strFile = a

Call Shell(strProg & " " & strFile, vbMaximizedFocus)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top