Launching a pdf file located in the current project path - ms-access

I want users to be able to put the Project folder on any location of their choice. If I use:
Application.FollowHyperlink ("C:\Program Files(x86)\Project\reference.pdf")
The pdf document launches only if the user put the Project folder in the Program Files(x86) folder. Is there a way for access to refer to the current path instead? I have tried the below code with no luck.
Private Sub referencefile_Click()
Application.FollowHyperlink (".\reference.pdf")
End Sub
I have tried:
Application.FollowHyperlink (CurrentProject.Path & "\reference.pdf"),
NewWindow:=True
This works well with txt files but not with pdf files. Any idea?

After a Quick Check and ensuring that my pdf file was not corrupted.
Application.FollowHyperlink (CurrentProject.Path & "\reference.pdf"), NewWindow:=True
The above code works fine as long as the pdf file exits in the same location as the front end. If you have ever thought of eliminating the security warning that access gives when you manually enter a hyperlink to a control button's properties, this code may be a good solution.

Related

run-time 2737 when connecting OLE Object (Word file) who is inside OneDrive Folder

I'm developing a solution based on Word and Access.
In an Access mask, the user click a command and a Word file is automacilly created and inserted in a BoundObjectFrame via the following command:
With OleDoc
.Class = "Word.Document"
.OLETypeAllowed = acOLELinked
.SourceDoc = strFullNameFile
.Action = acOLECreateLink
End With
Everything is fine if the file named strFullNameFile is in a normal folder on my computer. But if is in a subfolder inside my OneDrive folder in my computer, I get a
Run-time error 2737
Impossible to find file with OLE object linked...
Do you have any idea why?
Thanks, Lauro
You need to pass the path with subfolder too.
It's searching the file in main folder.

Display PDF in Report

I want to display dynamically .pdf files like pictures in a report, it should look like this:
i already tried with webbrowser, but then it doesn't show up in the preview or when i print the report out...
I also tried a ole unbound object, also no success, here the code i had in the Report_Load event:
Dim vPath As String
vPath = GetNewestDocument(Me!artNr)
'Returns path for pdf file, about:blank if there is no file.
If vPath = "about:blank" Then
Me!PDFBrowser.visible = True
Me.PDFBrowser.SourceDoc = vbNullString
Else
With Me.PDFBrowser
.OLETypeAllowed = acOLELinked
.SourceDoc = vPath
.SizeMode = acOLESizeStretch
End With
End If
EDIT:
With "I want to display dynamically ..." i meant to change dynamically pdf's in the Report.
EDIT 2:
I just found out that the type of the OLEunbound object is embedded, but i think this one should be linked as i read in other Forums:
When i try to Change it gives error: "This property can not be changed because it is read-only"
You could get a licensed version of Adobe Acrobat (not Reader) and control it programmatically to capture the images you want.
Alternatively, you could use the VBA Shell Function to call a command-line PDF converter like 2Jpeg to programmatically (and dynamically if necessary) convert the PDF to an image (see this), or even "print" the PDF to an image file using the correct driver (see this).
Once you have an image file, you can easily load the created image to your Access form with VBA, perhaps with this.
Without further information (and answers to my previous questions) I can't offer more suggestions at this point but I hope that helps!

Get file path of open file dialogbox

I am wanting to get the file directory of an already open file dialog box opened by internet explorer. I used the FindWindow() API to get the correct filedialog box. But my question is how to get the file directory from that dialogbox.
I know how to get it from one that was opened using the following.
Application.FileDialog(msoFileDialogFilePicker)
But not from one that is allready open.
Edit:
Would something like Dim FileDialog as New msoFileDialogFilePicker work? I'm not sure if thats the correct Syntax

Creating a Document Database using Microsoft Access

I am attempting to create a table within a database which store all of the documents related to the database "in it". What I really want to do is have a file uploaded and have vba code which copies the file to a network location, renames the file by concatenating two fields from the document table form (eliminating the issue of duplicate file names in the external location), and then stores the file name and file path in a file path field in the table. I am very new to access and vba so I am having difficulty getting everything to work. The code I currently have is below:
Option Compare Database
Private Sub Command15_Click()
Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = False
If f.Show Then
For i = 1 To f.SelectedItems.Count
sFile = Filename(f.SelectedItems(i), sPath)
MsgBox sPath & "---" & sFile
Next
End If
End Sub
Public Function Filename(ByVal strPath As String, sPath) As String
sPath = Left(strPath, InStrRev(strPath, "\"))
Filename = Mid(strPath, InStrRev(strPath, "\") + 1)
End Function
I can not seem to get a handle on how to move, rename by concatenating the two fields from the form, or store the path in the path field of the table. I have been to the following locations to obtain what information I could
ms access browse for file and get file name and path
VBA to copy a file from one directory to another
I am currently using Microsoft Access 2010, and I do not wish to use the file attachment field type because of database size constraints. Currently I press a button and a file explorer appears to navigate to the file being uploaded, and the path and file name are entered into strings. After this point I am lost. If any other information is needed please let me know. Thanks in advance for the assistance.
I believe your approach to managing the documents is right. In most cases, it doesn't make much sense to store documents in the database itself when the filesystem is a more suited to this job.
What you are doing is fairly straightforward but the main complexity will come from the correct management of the various paths and filenames and extracting the right information from them.
It can become tricky if you're not using some helper functions to to dissect and recompose the various bits of the paths.
I have created a sample database that has a few functions. Might not be exactly in line with what you need but you can easily play around with it to suit your particular case.
The sample database includes a Tools VBA module that has a few useful functions to split a Path into its constituents.
Basically, the database has 2 forms.
The main form allows you to set the network path where the files are to be saved.
You can then select a pre-defined Account number (listed in the Account table) associated with a document, then click the upload button.
This creates a new record in the Document table and opens a form where you can edit the document title and click a button to upload a file to the server.
The file selected by the user is copied to the server after its path has been transformed.
I took the assumption that the file would keep its original extension, the filename would be renamed to the ID of the Document record where the file information is saved (like 5845.pdf) and that the folder where the file is saved on the server would be the account number, so that a source file selected by the user
C:\Users\user\Desktop\SuperSecretFile.pdf
would be saved as, for instance:
\\docserver\files\123-55547\5845.pdf
The Main form also allows you to update an existing record, open the file from the server, open the server's folder where the file is located or even copy the server file back to the user's computer with the original name of the file.
I'll let you play around with it. Let me know if you have any issues.

Access 2007 - Display PDF content on a form

On Access 2007, is there a way to display the content of a PDF, even if it is just the first page, on a form? This PDF saved in a table as attachment.
Disclaimer: This answer will only work for PDF files stored outside of your database as separate file. They can be located over a network connection, but I do not know how to access them directly from your database table. This site gives a thorough guide to using the attachments, but doesn't show how to actually display them automatically. It is likely functionality not provided by Access.
You can display anything Internet Explorer can display with a Microsoft Web Browser Control.
Once you've added the control, you can navigate to whatever you want to display during the load or open event of the form.
For example, if the control is called WebBrowser0 then the following would work:
Private Sub Form_Load()
Me.WebBrowser0.Navigate2 "C:\example.pdf" 'Substitute the actual address here.
End Sub
This is an extremely versatile method for displaying other content within Access. You can find more information here.
The only two methods I know of for previewing a PDF (WebBrowswer as suggested by Daniel and the Adobe Active X control) require a file path to be passed to the control.
I recommend extracting the file from the attachment field and saving it to a temporary location such as C:\Documents and Settings\username\AppData. This can be found by using the vba Environ command.
Extracting the file is done with the SaveToFile method in the embedded DAO recordset (which is how attachments are stored in memory).
Example Code
Assume each record has a field called AttachedFile and each record has only one attached PDF. The form is using a WebBrowser control named PreviewBrowser to view the PDF
Private Sub Form_Current()
On Error GoTo ExitSub
Dim FormRS As DAO.Recordset
Set FormRS = Me.Recordset
Dim RecAtt As DAO.Recordset
If (Me.AttachedFile.AttachmentCount > 0) Then
Set RecAtt = FormRS.Fields("AttachedFile").Value
RecAtt.OpenRecordset
Dim Path As String
FilePath = Environ("APPDATA") & "\Preview.pdf"
If (Dir(FilePath) <> "") Then Kill FilePath
RecAtt.Fields("FileData").SaveToFile FilePath
Me.PreviewBrowser.Navigate2 FilePath
End If
ExitSub:
RecAtt.Close
End Sub
Of course the code needs to be a bit more complicated if there are multiple attachments to a given record, but that would be done by manipulating the RecAtt recordset.