## Add file location or files to a record

Discuss the database features

### Add file location or files to a record

I am trying to add a form field or box to associate external PDF files with a particular record. Can anyone help?

Thanks.
OpenOffice 4.1.7 on Windows 10
asiegelson

Posts: 11
Joined: Fri Apr 03, 2020 5:14 pm

### Re: Add file location or files to a record

On the General tab of the Push Button Properties dialog for a Push Button control on a Form set Action to Open document/web page.
Directly below is URL, place the filename with the complete path there and when the button is pressed it will open that document. Of course that requires a button for each pdf file, which isn't very practical if you have very many pdf files. In that case a macro is required to insert a filename and path stored in a field of your database table. Look here for an example
Hyperlink buttons for files, emails and other URLs
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.8 & LibreOffice 6.4.7.2 - Windows 10 Professional
UnklDonald418
Volunteer

Posts: 1407
Joined: Wed Jun 24, 2015 12:56 am

### Re: Add file location or files to a record

Thanks so much for the help. I was hoping to create a table (associated to records) to store the files or file directories where the user can add entries and/or click on the files to open them or open a windows explorer window to view. Also, I would ideally like a dialog similar to "save as" to add the files names or directories to the table.

Any ideas would be extremely helpful.

Thanks.
OpenOffice 4.1.7 on Windows 10
asiegelson

Posts: 11
Joined: Fri Apr 03, 2020 5:14 pm

### Re: Add file location or files to a record

You are right. My Python macro reads a file path or some valid URL from a database field and assigns the URL to a button which should open the resource when you click on it.
Here is a quick and dirty macro which opens a file-open dialog and writes the resulting file URL into a specified database field. Create a push button, assign the execute event to PickFileURL_Button AND write the name of the target column (name of table column, not the name of a form control) into the button's "Additional info". Take care that the button belongs to the right form or subform (the one having the target column).
Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****Const cDialogTitle = "URL Button File Picker"REM label and pattern for the file pickerConst cFilterLabel = "All Files (*)"Const cFilter = "*"REM ths defaults to the default document path of the office suiteREM use system notation C:\foo\bar\ or /home/user/foo/bar respectivelyConst cInitPath = ""REM write a file URL into a database field which is specified REM in the "Additional info" field of a push buttonSub PickFileURL_Button(e)   sInitPath = convertToURL(cInitPath)    f = pickFile(cDialogTitle, sInitPath, cFilterLabel, cFilter)    if f <> "" then        oModel = e.Source.getModel()        s = oModel.Tag        oForm = oModel.getParent()        oColumn = oForm.Columns.getByName(oModel.Tag)        oColumn.updateString(f)   endifEnd SubFunction pickFile(sTitle$, sInit$, sFilterLabel$, sPattern$) As StringREM return a single file URL or ""REM dialog starts at office default directory if sInit = ""Dim oPicker, x()   oPicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")   oPicker.setTitle(sTitle)   oPicker.setDisplayDirectory(sInit)   oPicker.setMultiSelectionMode(False)   oPicker.appendFilter(sFilterLabel, sPattern)   if oPicker.execute() then      x() = oPicker.getFiles()      pickFile = x(0)   endifEnd Function
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice

Villeroy
Volunteer

Posts: 30112
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany