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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a PDF from a form 2

Status
Not open for further replies.
Jan 14, 2003
194
US
The form lists the equipment assigned to an employee. This equipment is issued and an agreement form is signed and then scanned as a PDF. These PDFs are stored in a subdirectory in the same dir as the Access Database.

I want to be able to link from the form to the associated PDF for that user. How do I place a link on the form that uses the full name of the user (firstlast.pdf - no spaces) as the name of the PDF file to open, automatically inserting the full network UNC path (\\servername\path\) before it? That way, if a user doesn't have an agreement form, it will just error that no such document exists.

Thanks!!
 
You can paste this function into a module:

Function OpenPdf(SrvPath As String, UserName As String)
Application.FollowHyperlink SrvPath & UserName & ".pdf"
End Function

Then place this code in the on click event of your button:


OpenPdf "C:\", "IsomEric"


Where "IsomEric" should be replaced by the username or variable that stores the username.

HTH,
Eric
 
The first name and last names are two separate fields on the form. I want this code to pull those two fields together without any spaces to use as the filename.

Looks like the above requires that I manually enter it?
 
You just need to pass the user name to the function.

Example:
OpenPdf "C:\", me.lastname & me.firstname


Where lastname and firstname are the names of your fields in your form.

HTH,
Eric
 
So Change it to:
Code:
Function OpenPdf(SrvPath As String, FirstName As String, LastName As String)
    Application.FollowHyperlink SrvPath & FirstName & & LastName ".pdf"

End Function


OpenPdf "C:\", FirstName, LastName

HTH
Mike

[noevil]
 
Thanks to both of you for the help!! I had to remove the 2nd & between the names and the PDF part, as well as add a & before the PDF. But it works wonders!!

Now, I didn't realize that I'd get a debug box when trying to open a non-existent file. What can I add to the on-click event to produce some other message (preferrably something like a small pop-up box stating "There is no Inventory form for this user")

Thanks again!!!

PS. Can you tell I'm a total n00b when it comes to this stuff?
 
Add error handling.

Code:
Function OpenPdf(SrvPath As String, FirstName As String, LastName As String)
    Application.FollowHyperlink SrvPath & FirstName & LastName  & ".pdf"

End Function

On error goto ErrX
OpenPdf "C:\", FirstName, LastName
exit sub
ErrX:
msgbox "There is no inventory form for this user.",vbokonly,"Error"

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top