Page 1 of 1

Add file location or files to a record

Posted: Tue Dec 01, 2020 7:42 pm
by asiegelson
I am trying to add a form field or box to associate external PDF files with a particular record. Can anyone help?


Re: Add file location or files to a record

Posted: Wed Dec 02, 2020 5:19 am
by UnklDonald418
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

Re: Add file location or files to a record

Posted: Wed Dec 02, 2020 3:55 pm
by asiegelson
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.


Re: Add file location or files to a record

Posted: Wed Dec 02, 2020 4:31 pm
by Villeroy
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

REM  *****  BASIC  *****
Const cDialogTitle = "URL Button File Picker"

REM label and pattern for the file picker
Const cFilterLabel = "All Files (*)"
Const cFilter = "*"

REM ths defaults to the default document path of the office suite
REM use system notation C:\foo\bar\ or /home/user/foo/bar respectively
Const cInitPath = ""

REM write a file URL into a database field which is specified 
REM in the "Additional info" field of a push button
Sub 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)
End Sub

Function pickFile(sTitle$, sInit$, sFilterLabel$, sPattern$) As String
REM return a single file URL or ""
REM dialog starts at office default directory if sInit = ""
Dim oPicker, x()
	oPicker = CreateUnoService("")
	oPicker.appendFilter(sFilterLabel, sPattern)
	if oPicker.execute() then
		x() = oPicker.getFiles()
		pickFile = x(0)
End Function