I have a standard LibreOffice database form that displays a photo of an event/person whose path is indicated in the table. So far so good, however, since the form space is uniform and not very large, I would like to be able to double-click on the image to open the file in a separate window in its original size format. Is this possible? And if so, can you help me? Thank you.
- Download and install
URLButton.py.odt (25.0 KB) No need to modify nor understand anything. Use this macro as is. - Modify the source of your (sub-)form, so it includes the absolute full picture path. If the form was bound to some table “PICS” with a text field “FILE” holding the file names, switch the source to query
SELECT "PICS".*, 'C:\full\path\' || "FILE" AS "PATH"which returns the entire table plus an extra column with the concatenated full path. - Add a push button to the same (sub-)form.
3.1. Assign the button’s approve event to MyMacros>pyDBA>FileButton_Approve
3.2. Add the field name with the full paths to the button’s additional info,PATHin this scenario.
Now, the push button opens the picture file in the default file viewer application of your operating system.
Don’t know if it works on Windows or macOS 
Event = Image Controls > Mouse button pressed
CtrlClick on the image:
Option Explicit
Sub ViewImage(oEvent As Object)
Dim oDoc As Object, oShell As Object
Dim stUrl As String, stField As String
Dim arUrl_Start()
On Error GoTo Erro
If oEvent.Modifiers = 2 Then
oDoc = ThisComponent
stField = oEvent.Source.Model.BoundField.getString()
oShell = createUnoService("com.sun.star.system.SystemShellExecute")
arUrl_Start = split(oDoc.Parent.Url, oDoc.Parent.Title)
stUrl = convertToUrl(arUrl_Start(0) + stField)
oShell.execute(stUrl,"", 0)
End If
Exit Sub
Erro: MsgBox "ERRO " & Err & Chr(10) & "na linha " & Erl
End Sub

Muito obrigado Carlos. Funciona perfeitamente “Ctrl” + 1 Click sobre a foto. Era exactamente o que eu pretendia. Mas, infelizmente, eu olho para o código da macro e fico com a perfeita noção de que nunca a poderia ter escrito sozinho. Obrigado.
Ops…
Thank you very much, Carlos. It works perfectly: “Ctrl” + 1 Click on the photo. It was exactly what I wanted. But, unfortunately, I look at the macro code and I’m perfectly aware that I could never have written it myself. Thank you.
However, an error occurs when opening the file if the name has an accent mark. For example: “JosĂ© Coronado.jpg”, “VirgĂlio Castelo.jpg”, “Zöe Saldaña.jpg”, “TotĂł.jpg”, “Milène Demongeot.jpg”, etc…
Which means I will have to change the name of all files with accent marks. Which won’t be a big deal!
Dear Villeroy, thank you very much for your reply and for the time you dedicated to it. I tried the macro sent by CRDF and it worked perfectly, so I didn’t try yours, which seemed more complicated, although I don’t take away any credit from you. Thank you very much.
You can try this code as a function (build a function with a string parameter returning a string) ON ANOTHER FORM.
Ref: Google AI
Option Explicit
Sub EscaparAcentos
Dim oFunctionAccess As Object
Dim original As String, convertido As String
REM Set the original url as a string:
original = "file:///home/Quaresma/EstudosDBs/BancoImagens/Zöe Saldaña.jpg"
On Error GoTo Erro
REM Create the FunctionAccess service
oFunctionAccess = CreateUnoService("com.sun.star.sheet.FunctionAccess")
REM Call the Calc function using its English name - parameter must be as an array!
convertido = oFunctionAccess.callFunction("ENCODEURL", Array(original))
print convertido
Exit Sub
Erro: MsgBox "ERRO " & Err & Chr(10) & "na linha " & Erl
End Sub
Â
stUrl = convertToUrl(arUrl_Start(0) + stField)
stUrl = FuncaoEscaparAcentos(stUrl)
oShell.execute(stUrl,"", 0)
I’m unable to check it becase don’t have non ASCII or blanks in addresses.

The problem is in these lines:
arUrl_Start = split(oDoc.Parent.Url, oDoc.Parent.Title)
stUrl = convertToUrl(arUrl_Start(0) + stField)
Replace description:
Dim arUrl_Start()
to
Dim arUrl
and use this version of the fragment:
arUrl = Split(ConvertFromUrl(oDoc.Parent.Url), GetPathSeparator())
arUrl(UBound(arUrl)) = stField
stUrl = ConvertToUrl(Join(arUrl, GetPathSeparator()))
Additional bonus: the document’s Title property, which can be changed by the user or a macro, is not used.
Changed the code to yours 
Of course I’m unable to check the accent marks + blanks as don’t have them.
Â

Hello Carlos. I tried modifying the previous code, changing the line:
Dim arUrl_Start()
to
Dim arUrl
and the lines
arUrl_Start = split(oDoc.Parent.Url, oDoc.Parent.Title)
stUrl = convertToUrl(arUrl_Start(0) + stField)
to
arUrl = Split(ConvertFromUrl(oDoc.Parent.Url), GetPathSeparator())
arUrl(UBound(arUrl)) = stField
stUrl = ConvertToUrl(Join(arUrl, GetPathSeparator()))
And it resulted in an ERROR, whether the filename had accents or not.
So, I’m sticking with the previous code. I must be doing something wrong, for sure. I’ll just have to waste a lot of time removing the accents from the names of actors and films with accents. The spaces between the names were never a problem, only the accents. Thank you for trying.
@sokol92’s code works fine here to me.
Â
Please format code com 3 acentos graves:
```
the code
```
I´m sorry Carlos, where exactly should I put the three grave accents in the code? Before and after what? Thank you, and excuse my ignorance.! 
The code, like
```
arUrl = Split(ConvertFromUrl(oDoc.Parent.Url), GetPathSeparator())
arUrl(UBound(arUrl)) = stField
stUrl = ConvertToUrl(Join(arUrl, GetPathSeparator()))
```
So the code gets formatted like code:
arUrl = Split(ConvertFromUrl(oDoc.Parent.Url), GetPathSeparator())
arUrl(UBound(arUrl)) = stField
stUrl = ConvertToUrl(Join(arUrl, GetPathSeparator()))
It’s funny, it keeps giving an error, now of a different nature. Could you tell me where I can read more about this to better understand this type of encoding preceded by 3 backticks? Thank you.
Misunderstanding 
Backticks here in the messages to renderize
the code text. Not in the macro itself.
Â
I’m not with the same machine now, but will try to build an example using @sokol92’s code.
Â
EDIT
It didn’t work to me here. Named a photo as
öe ña.jpg
and

Hello!
Sorry, I didn’t notice how exactly stURL was used.
In this case, the filename is expected in the operating system format.
So try this:
stUrl = Join(arUrl, GetPathSeparator())
I just tested this part of the code for Windows – no error is thrown.

- OS W-11
- Subfolder BancoImagens
-
Photo öe ña.jpg (oculo del Pantheon of course)
Â
Â
Â
But using ImageControl it’s the same error. It looks like the OS separator question. Will check on Linux tomorrow.
Â
Yes, as I can see a slash behind BancoImagens, while backslash is used for the first part. I guess mixing separators in one path is no good idea.
.
But there seems also to be active url-encoding for the filename.
.
Can’t test today, but I think for ShellExecute we need a regular path for the OS and may even need to use the same encoding as the shell itself. Utf8 can not be assumed valid for Windows.
I’m astonished of the example with space in name, aa I had expected this to need quotes.
.
On the other hand: An url-encoded name should work for a hyperlink to a file://-resource
On Linux Mint 21.3 Cinnamon now
Made a copy of my photo “Adrar.jpg” as “öe ña.jpg” and “my” original code is working
both in
- form with Image Control: Ctrlclick on the image;
- form (Table2) with TextBox for the Path string: Ctrlclick on the TextBox.



Could you upload a test file (*.odb)?
- There are 2 kinds of forms:
Imagens with an Image Control — as per OP. This is not working for non ASCII.
Source = table IMAGENS.
Paths only a TextBox with the path to image. This runs
Source = table PATHS. - Of course place the images in subfolder.
- Please take notice that for the Image Control Base % encodes non ASCII paths. I imagine
this is the issue on Windows.
On Linux all works
here.
Of course I’m doing this in a W-11 machine now.
Â
Fotos.odb (19.6 KB)





