Displaying a PDF document link in a form (1 Viewer)

crann

Registered User.
Local time
Today, 19:43
Joined
Nov 23, 2002
Messages
160
Hi Guys

Advice on how best to display a link to a PDF file or image from a form.

I have a table which contains information about safety records.
Within the table I have a field called: GasCheck.
This field contains the file path to a scanned copy of a Gas Safety Certificate or PDF document.

I want to display an icon that a user can click to launch that specific file, specific to the record im on and then go on to print etc.

I have been able to display for example a .jpg image but not able to click the icon and actually print it or view it within its own programme, PDF's i cant seem to view at all

Can I do what I am trying to do and how?

Thanks
 

spikepl

Eledittingent Beliped
Local time
Today, 20:43
Joined
Nov 3, 2010
Messages
6,144
look up FollowHyperlink method
 

crann

Registered User.
Local time
Today, 19:43
Joined
Nov 23, 2002
Messages
160
Thanks

OK heres the problem I am having work great if I set the field to a Hyperlink the problem is I share the table information on Sharepoint. For some reason sharepoint wont let me upload table with the hyperlink fields in.

Is there anyway I can keep field as Short Text with the path stored then change the text field on form to open that path as a hyperlink??

Thanks
 

spikepl

Eledittingent Beliped
Local time
Today, 20:43
Joined
Nov 3, 2010
Messages
6,144
Read the documentation for the FollowHyperlink method
 

crann

Registered User.
Local time
Today, 19:43
Joined
Nov 23, 2002
Messages
160
Thanks

Yes I have already been reading many posts but as a beginner struggling to stay on track.

Ive used the code Application.FollowHyperlink for example to open open files etc but Im not sure how I get the code to look for the specific path of each different record within the table. My Hyperlinks just seem to open a fixed path.

I am very happy to read and learn myself i just cant seem to find a post specific to what i am trying to do.

Any help be grateful

Thanks
 

smig

Registered User.
Local time
Today, 21:43
Joined
Nov 25, 2009
Messages
2,209
I use this code:
Code:
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, 
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Function OpenDirApp(WhatToOpen As String)

ShellExecute 0, "Open", WhatToOpen, vbNullString, vbNullString, SW_SHOWNORMAL

End Function
You can send this function whatever you want - Application name (Winword.exe), a file or folder.

It's a function so it can be called from Menu buttons, but it can be a Sub too.
 

HiTechCoach

Well-known member
Local time
Today, 14:43
Joined
Mar 6, 2006
Messages
4,357
Thanks

OK heres the problem I am having work great if I set the field to a Hyperlink the problem is I share the table information on Sharepoint. For some reason sharepoint wont let me upload table with the hyperlink fields in.

Is there anyway I can keep field as Short Text with the path stored then change the text field on form to open that path as a hyperlink??

Thanks

Are you creating a Web App?

Have you considered storing the files in Shaerpoint?
 

crann

Registered User.
Local time
Today, 19:43
Joined
Nov 23, 2002
Messages
160
Hello

No my db is not a web app. In simple terms I have a copy of the db local on a few different machines but have my tables stored in Sharepoint so data is always saved securely and shared by any user.

I have a business One Drive Account which ive created as a mapped netword drive labelled Z:\ drive. All my files are then saved from any machine to that shared z:\ and I simply reference that path from a Table field within the db.

I have managed to use the following code to access different scanned files from within my form:

Application.FollowHyperlink "Z:\FireCertificates\" & Me.BuildingCode & ".PDF"

In this case when I scan a document I save the name as the Building code which also appears in my form, different for each record. That seems to work really well and actually is quite logical that I save the scanned ducument with a related file name such as the building number.

The only thing is if there are no files scanned in when I click the command button I get and error message appear is it possible to add some code to say if no file is saved display a message box "Please scan a new document" ???

Hope that makes sense.

Thanks
 

HiTechCoach

Well-known member
Local time
Today, 14:43
Joined
Mar 6, 2006
Messages
4,357
Hello

No my db is not a web app. In simple terms I have a copy of the db local on a few different machines but have my tables stored in Sharepoint so data is always saved securely and shared by any user.

I have a business One Drive Account which ive created as a mapped netword drive labelled Z:\ drive. All my files are then saved from any machine to that shared z:\ and I simply reference that path from a Table field within the db.

I have managed to use the following code to access different scanned files from within my form:

Application.FollowHyperlink "Z:\FireCertificates\" & Me.BuildingCode & ".PDF"

In this case when I scan a document I save the name as the Building code which also appears in my form, different for each record. That seems to work really well and actually is quite logical that I save the scanned ducument with a related file name such as the building number.

The only thing is if there are no files scanned in when I click the command button I get and error message appear is it possible to add some code to say if no file is saved display a message box "Please scan a new document" ???

Hope that makes sense.

Thanks

Sure us the Dir() function to test to see if the filr exist before attempting to opening it.

I recommend that you always test to see if a filr exist before trying to use it.


Example: **** Untested****
Code:
Dim strFilePath as String


strFilePath  = "Z:\FireCertificates\" & Me.BuildingCode & ".PDF"

if Dir(strFilePath ) > "" then 

   Application.FollowHyperlink strFilePath  

Else

  MsgBox "Not Found"
End if
 

smig

Registered User.
Local time
Today, 21:43
Joined
Nov 25, 2009
Messages
2,209
Did you try what I suggested ?
 

crann

Registered User.
Local time
Today, 19:43
Joined
Nov 23, 2002
Messages
160
Thanks for that HiTechCoach worked perfect and makes total sense now to test if a file exists first in the code.
 

Users who are viewing this thread

Top Bottom