Access Macro to Open a PDF

G

Guest

I would like to create a Macro linked to a button on a form in access 2003
that would take a field entry and open a PDF file in Acrobat Reader with the
same file name as the field entry. Is this possible? Can a novice (me)
understand your solution?
 
T

tina

i don't think you can do it in a macro. but if you're willing to give VBA a
try, then open the module window behind any form and search the VBA Help for
FollowHyperlink

hth
 
G

Guest

That was a helpful respopnse, but I don't know enough about VBA. I'll study
up though. Thanks.
 
T

tina

yes, that was a pretty brief answer; had system problems and couldn't get
into my Access program. i set up the very thing you're describing: created
a table with two records, one containing the filepath to Adobe Reader on my
PC, and the other containing the filepath to the folder holding the files i
want to open. the filenames are in another table that i update periodically
as new files are added to the folder. in the data entry / search form bound
to the second table, i added a command button to run the code that opens
Adobe Reader and then opens the PDF file i'd selected in the search form.
code is posted below; note that i've just copied my specific code as an
*example*, so you'll need to replace tablenames, fieldnames, controlnames,
etc. for illustrated instructions on how the create a VBA procedure in a
form module, go to http://home.att.net/~california.db/instructions.html and
click the CreateEventProcedure link. also, read up on DLookup() function,
Shell, and FollowHyperlink in Help, so you'll understand how they work.

hth

Private Sub cmdLink_Click()

On Error GoTo cmdLink_Err

Dim str As String

str = DLookup("fpPath", "tbl00FilePaths", "fpID = 6") _
& Format(Me!ChildDetails.Form!docDate, "yyyy_mmdd_") _
& Nz(Me!ChildDetails.Form!docLtr, "A") & ".pdf"

Shell DLookup("fpPath", "tbl00FilePaths", "fpID = 7"), _
vbMaximizedFocus

Application.FollowHyperlink str, , , False

cmdLink_End:
Exit Sub

cmdLink_Err:
Select Case err.Number
Case 432 ' filepath not found.
MsgBox "The filepath is incorrect." _
& vbCr & vbCr _
& "Sorry, you'll have to open the PDF " _
& "file manually from Windows Explorer."
Resume cmdLink_End
Case 53 ' file not found
MsgBox "The Adobe Acrobat program was not found." _
& vbCr & vbCr _
& "Sorry, you'll have to open the PDF " _
& "file manually from Windows Explorer."
Resume cmdLink_End
End Select

End Sub
 
S

Steve Schapel

Jwaldo,

Make a macro using the RunApp action.

In the Command Line argument of the macro, enter the equivalent of this...

=Chr(34) & 'C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe' &
Chr(34) & ' ' & Chr(34) & [Forms]![YourForm]![YourTextbox] & Chr(34)

Save this macro, and then assign it on the Click event of your command
button.

My example uses Adobe Reader 8. You will need to check the path to the
program file for your version.
 

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