Macro to open a PDF file in the same directory

I have made a database to manage a collection of PDF documents where they can be selected by date, subject and persons envolved. It works perfectly but now I decided to add an action button to the form to open the document and I’m having difficulties creating a macro to open them.
In the form I have a text box named (txtPDF) connected to the table field (pdfName) where the pdf file folder and names are inserted (archive/001.pdf …) and the action button in the form named (openPDF) is set to “Opendocument/webpage”.
My macro is:

Sub GetPDF
oForm = ThisComponent.Drawpage.Forms.getByName(“MainForm”)
DocCtl = ThisComponent.getCurrentController()
oField = oForm.getByName(“txtPDF”)
oButton = oForm.getByName(“openPDF”)
CtlView = DocCtl.GetControl(oField)
oButton.TargetUrl = CtlView.Text
end sub

Can I have a little help? I don’t want you to make me a database, just tell me where I went wrong and if possible a little example. Thank You.

You will need to open the *.pdf by the shell:

stField = convertToUrl(oField.currentValue)
oShell = createUnoService("com.sun.star.system.SystemShellExecute")
oShell.execute(stField,,0)

The URL will be relative. So you will also have to read the URL for your database file to get the right URL:

 oDoc = ThisComponent
 oField = oForm.getByName("txtPDF")
 stUrl = oField.BoundField.getString
 arUrl_Start = split(oDoc.Parent.Url,oDoc.Parent.Title)
 oShell = createUnoService("com.sun.star.system.SystemShellExecute")
 stField = convertToUrl(arUrl_Start(0) + stUrl)
 oShell.execute(stField,,0)

I think that you can probably do this without using the shell.
bind the code to the button using the Approve action event.
NOTE: line 5, replace YOUR DATABASE NAME with the name of your database.

EDIT: added missing ) after - 1

Sub GetPDF(oEv as object)
	dim oButton as object, oForm as object, oTextBox as object
	dim sDB as string, sLocation as string, sPath as string, sTxt as string, sFilePath as string
	
	sDB = "YOUR DATABASE NAME.odb"

	sLocation = thisdatabasedocument.location
	sPath = left(sLocation, instr(sLocation, sDB) - 1)

	oButton = oEv.source.model
	oForm = oButton.parent
	oTextBox = oForm.getbyname("txtPDF")
	sTxt = oTextBox.text
	sFilePath = sPath & sTxt
'print sFilepath : exit sub
	oButton.targeturl = sFilePath
End Sub

Thank you cpb. I only saw your answer today and I want to thank you for the solution of my problem. I tried it on my database and it worked fine. Thankx man, you’re great!