[Solved] Opening a file or folder from a Base form

Creating and using forms
Post Reply
Wendor
Posts: 2
Joined: Fri Feb 12, 2016 9:09 pm

[Solved] Opening a file or folder from a Base form

Post by Wendor »

I have a database in which I am cataloging a bunch of children's crafts used during story time at my library. Each craft has a folder which contains an image of the completed craft and printable files of the paper pieces needed to make it. I would like to include a function on the form where users can open the folder containing those files from the form itself. There are some records in the database that are also generic master sheets that can be used on any number of crafts and I would like to be able to open those files directly from the form. The current workaround I am using is to include a "Folder Location" field that displays the folder address so it can be copied and pasted into Windows Explorer. However, this is proving confusing to some coworkers. If its possible I would like to use a push button or some other function to open it directly from the form.

I know that Push buttons and Image Buttons can be commanded to open a document or url, however it looks as though I have to select one url that will be opened by the button regardless of what information is in the record I'm looking at. Is it possible to command one of these to pull information from my "Folder Location" field and open the address that field contains?

Thank you, I would greatly appreciate any insight
Last edited by RoryOF on Wed Feb 17, 2016 12:23 am, edited 1 time in total.
Reason: Added [Solved] and green tick [RoryOF, Moderator]
LibreOffice 4.4.0.3, Windows 7 64-bit
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Opening a file or folder from a Base form

Post by UnklDonald418 »

Here is a macro I once found on this forum that might do what you are asking. It reads a valid Windows file path (URL) from a form and opens it with the Windows default program for that file type.

It requires a few changes to get it functioning in each situation.

First you need a button to activate it. Then two Button->Control->Properties must be adjusted.
1) Event->Approve Action needs to be connected with this macro.
2) under General->Action select “Open document/webpage”

In the macro text itself you will need to enter the name of the Grid that contains the file names, in the example it is “Subform_Grid”, and the name of the column/field that contains the file names, in the example it is “LInk”. In your case it would probably be "Folder Location" .

You can find the Grid name using the Form Navigator.

Code: Select all

REM  *****  BASIC  ***** 

' You need two controls in your form(document). They must be in the same form(as in navigator).
' One control is a text control and contains the pathname or url to the file.
' The second control is a button.
' The action is bound to the first event of the button control: Before commenting
' The name is new in OOo3.2 and later : Approve action
' The function can be aborted when the files does not exist.
' You also have change the properties of the button control.
' The action is :Open document/webpage.
' The small macro moves the field value from the textbox to the button control url
function openurl(oEv as object)

   dim oForm as object
   dim oTextBox as object
   dim oTextBoxtest as object
   dim oMRI as Object
    
oDoc = ThisComponent
   oForm=oEv.source.model.parent
   oTextBox=oForm.getbyname("SubForm_Grid").getbyname("LInk")
      if FileExists ( oTextBox.text) then
        oEv.source.model.targeturl=oTextBox.text
        openurl=true ' Do the program when the file exists
      else 
        openurl=false ' The file does not exist and do nothing
      end if
End function
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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Wendor
Posts: 2
Joined: Fri Feb 12, 2016 9:09 pm

Re: Opening a file or folder from a Base form

Post by Wendor »

Worked like a charm! Thank you so much!
LibreOffice 4.4.0.3, Windows 7 64-bit
Post Reply