Push Button to open external PDF files or URLs from a form in Base

Hello. I am using LibreOffice 7.5.8 with Firebird interface on a Windows 11 desktop.
.
For each record in my form (named MainForm), I have:

  • a text field (txtMyPDF) that contains the path of a related PDF file stored on my computer.
  • a text field (txtMyURL) that contains the URL of a related website.

.
I am trying to add two push buttons (pbGetPDF and pbGetURL), one beside each text field that, when pushed, would open either the PDF file in my default pdf viewer or the URL file in my default browser.
.
Under the “General” tab of the Push Button, there is an “Action” section for which I can choose “Open document/web page”… BUT I don’t understand how to point the push button to the pathway listed in the appropriate text fields (txtMyPDF or txtMyURL).
.
Any help would be greatly appreciated!

IMHO you will need a macro to do the connection, but you may store the name of the “bound”-field in the attributes of the button as tag. Compare this solution for images:

Thank you for your reply, @Wanderer .
.
I read through the thread to which you directed me and tried to implement the macro, but unfortunately I was not successful. When I push the button to open the document, it throws a macro error message: “Variable not defined.” It doesn’t like the oEvent.Source.Model
.
The steps I took were as follows:

  • I created the macro provided in the thread by @RobertG .
  • In the “Additional Information” field for each push button, I entered the name of the field that contains the path and filename of the document I wanted to open.
  • In the “Execute” Event for each push button, I assigned the macro.

.
To clarify what I’m trying to do, I am attaching a scaled-down sample database.
InventoryDocs.odb (13.8 KB)

I tried to send it with the Item subfolders and sample documents, but the software wouldn’t let me send a zipped folder. So I have also uploaded one of the sample documents that I was trying to open with the push button.
SamplePDF.pdf (13.1 KB)

.
Does anyone see what I need to fix? Any help with this would be appreciated.

  1. If you get “Variable not defined”: Try with option explicit disabled. If it works: look for the variable. oButton isn’t listed there. I haven’t tested all with option explicit.
  2. Have a look at the name oft the textboxes: All Textboxes in your example start with txttxt…, but in tag of the button I could only see txt… one time. So the field couldn’t be found.
  3. You will try also to start URL. Then the macro has to be changed. I have rewritten the code here with possibility to start webbrowser, email and the “normal” connection to any document on your system. All variables are now included, so it will work also with option explicit:
SUB ShowImage(oEvent AS OBJECT)
	DIM oDoc AS OBJECT, oButton AS OBJECT, oForm AS OBJECT, oField AS OBJECT, oShell AS OBJECT
	DIM stImageControl AS String, stUrl AS STRING, stField AS STRING
	DIM arUrl_Start()
	oDoc = thisComponent
	oButton = oEvent.Source.Model
	stImageControl = oButton.Tag
	oForm = oButton.Parent
	oField = oForm.getByName(stImageControl)
	stUrl = oField.BoundField.getString
	IF stUrl <> "" THEN
		IF InStr(stUrl,"http") THEN
			stField = stUrl
		ELSEIF InStr(stUrl,"@") THEN
			stField = "mailto:" & stUrl
		ELSE
			arUrl_Start = split(oDoc.Parent.Url,right(convertToUrl(oDoc.Parent.Title),len(convertToUrl(oDoc.Parent.Title))-8))
			stField = convertToUrl(arUrl_Start(0) + stUrl)
		END IF
		oShell = createUnoService("com.sun.star.system.SystemShellExecute")
		oShell.execute(stField,,0)
	END IF
END SUB

Title of the procedure is now misleading. Might be OpenLink instead.
InventoryDocs.odb (13.8 KB)

THANK YOU very, very much, @RobertG ! :clap: :clap:
.
I have no idea how the double “txt” in the field name happened…
.
When I implemented the revised macro into my real database, it worked like a charm!
.
Trying to figure out this process had caused me a LOT of frustration, so I really do appreciate it.