Ask Your Question

In base how to open a URL field?

asked 2018-06-14 00:30:10 +0200

EasyTrieve gravatar image

updated 2018-06-15 19:48:44 +0200

If a text field holds a URL string, how can one easily open the link in your browser?

(A similar question is here:

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-06-14 00:41:46 +0200

EasyTrieve gravatar image

updated 2018-10-09 21:32:58 +0200

If you want to be able to select the URL and hit F9 to open it in your browser, then just install this macro for the control's KeyPressed event:

' --- If F9 key hit then execute the URL (i.e. show the file or web page) -------------'
Sub KeyPressedEvent(oEvent As Object)
  If oEvent.KeyCode = Then   'Adjust to suit your taste'

    '-Create the needed SystemShellExecute service object'
    DIM oShell AS OBJECT :oShell=createUnoService("")

    '-Get the URL from the current field'
    DIM s AS STRING      :s     =oEvent.Source.Model.CurrentValue : s = convertToUrl(s)

    '-Open the URL in your browser'
  End If
End Sub

Tip: So that when a user hovers over the text box field they get a tool tip, please also set the Help text property on the Control to something like:

Help text:   Hit F9 to open URL in your browser or other appropriate tool.

Updated Oct, 2018 to simplify and improve code.

edit flag offensive delete link more

answered 2018-06-14 00:57:48 +0200

Ratslinger gravatar image


I find using a button to be quite effective. With this macro:

Sub GetURL
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
    DocCtl = ThisComponent.getCurrentController()
    oField = oForm.getByName("txtURL")
    oButton = oForm.getByName("Push Button 1")
    CtlView = DocCtl.GetControl(oField)
    oButton.TargetUrl = CtlView.Text
end sub

attached to After record change event of form and on the push button property Action set to Open document/web page you only need a click of the button to open the link. Works well for opening other documents as well.

No need to use Shell.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-06-14 00:30:10 +0200

Seen: 1,865 times

Last updated: Oct 09 '18