Open File from Data in a table.

K

Kevbro7189

I have a table with a list of over 10,000 files. The table doesn’t contain a
location or file extension just the basic file name. I made a form to list
all the files. Next to each line I want a button to run macro to open the
specific file based on the data stored in the table. Below is the Macro I
have come up with so far. [Text6] populates automatically with the name of
the file in its proper file location when the button is clicked.

Macro
SetTempVar - WORKS
Name: PRTOPEN
Expression: [Forms]![Table1]![File] ----- The data is the file I want to open

SetTempVar - WORKS
Name: PRT1
Expression:
"C:\Users\Kevin \Documents\" & [TempVars]![PRTOPEN] & ".doc"-----This sets
the location

SetValue - WORKS
Item: [Forms]![Table1]![Text6]
Expression:
[TempVars]![PRT1]---This checks the output , the location and file are put
together correctly

RunApp -ISSUES
Command Line:
"C:\Program Files\Microsoft Office\Office12\winword.exe" =[TempVars]![PRT1]
------ Word opens but the file does not.
The error message is:
“The File could not be found (C:\user\...\=[TempVars]![PRT1].doc)â€

RemoveAllTempVars
 
P

Pendragon

In VBA code your final code would be

"C:\Program Files\Microsoft Office\Office12\winword.exe " & [TempVars]![PRT1]

Note the space after winword.exe. Also, your error message indicates that
Word is looking for a file with an '=' in the name. Perhaps try it without
the '='?

Otherwise, set your macros into VBA code for an event procedure in the
OnClick property of the button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top