[Solved] Form button to open url saved in a field?

Creating and using forms

[Solved] Form button to open url saved in a field?

Postby giooo » Thu Mar 04, 2010 12:17 pm

Hi everybody,

Say I have a table with a field containing web addresses.

In a form I'd like to add a button to open the browser to the web address stored in that record.
I thought of using a button with "open document/web page", but in that case the link is static.
See attached file for example. There's one table and one form.

Is it possible to pass somehow a field value to a button?
Any other strategies?

Maybe it's a trivial problem and I am missing something...
Thanks for any suggestions/help!

giooo
Attachments
db_link.odb
(11.33 KiB) Downloaded 548 times
Last edited by giooo on Fri Mar 05, 2010 10:19 am, edited 1 time in total.
OpenOffice 3.2 32-bit on Windows 7 Professional 64-bit
giooo
 
Posts: 6
Joined: Wed Mar 03, 2010 2:41 pm

Re: Form button to open url saved in a field?

Postby RPG » Thu Mar 04, 2010 3:20 pm

Hello

This routine must do what you asked You have to adjust some names.
For information how to connect a macro to an event see your help file

select first the help files.
then in the list box left in top : OpenOffice.org Base
tabpage index and type in : events;assigning scripts

Romke


Code: Select all   Expand viewCollapse view
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. ' Name before OOo3.2
' The name is new in OOo3.2 and later : Approve action
' The function can be aborted when the files does not exist.
' You have also change the properties of the button control.
' The action is :Open document/webpage.
' The small macro move the field value from the textbox to the button control url
function openurl(oEv as object)
'
   dim oForm,oTextBox
   oForm=oEv.source.model.parent
   oTextBox=oForm.getbyname("TextBox")
   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
   'print  convertfromurl(oTextBox.text)
End function


 Edit: I have edit some bugs. 
Last edited by RPG on Sat Jul 11, 2015 10:05 am, edited 1 time in total.
LibreOffice 6.0.4.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2132
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Form button to open url saved in a field?

Postby giooo » Thu Mar 04, 2010 4:55 pm

yup, it works! :-)

thank you very much!


giooo
OpenOffice 3.2 32-bit on Windows 7 Professional 64-bit
giooo
 
Posts: 6
Joined: Wed Mar 03, 2010 2:41 pm

Re: [Solved] Form button to open url saved in a field?

Postby tx42 » Tue Feb 11, 2014 9:31 pm

For opening a web URL, "FileExists" will usually hang and may crash OO!

:alarm: I abandoned opening web URLs with the macro above because it always hanged. I've since brushed up on my OO basic, and found the problem. It makes no sense to check if the file exists if the file is a web URL. Just check if its an empty string and let the browser do any further checking, etc. Here is a better version for opening web URLs based on the above code:

Code: Select all   Expand viewCollapse view
REM **********************************************************************
REM Open URL from button
REM       https://forum.openoffice.org/en/forum/viewtopic.php?f=39&t=28228
REM **********************************************************************
' 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 commencing. ' Name before OOo3.2
' The name is new in OOo3.2 and later : Approve action
' The function can be aborted when the files does not exist.
' You have also change the properties of the button control.
' The action is :Open document/webpage.
' The small macro move the field value from the textbox to the button control url
sub openURL(oEv as object, aTextName as String)
   dim oForm, oTextBox
   oForm=oEv.source.model.parent
   oTextBox=oForm.getbyname(aTextName)
   if (oTextBox.text <> "") then
      oEv.source.model.targeturl = oTextBox.Text
      openurl=true ' Do the programm when the file exists
    else
      openurl=false ' The file does not exist and do nothing
   end if
   'print  convertfromurl(oTextBox.text)
End sub

sub openURLtxtURL(oEV as object)
   openurl(oEv, "txtURL")
End sub


With these two subroutines, you can reuse the openURL subroutine for text boxes of different names by defining different stubs. The above stub called "openURLtxtURL" opens the URL in the text box called "txtURL".
NeoOffice 3.2 on OS X 10.6
tx42
 
Posts: 3
Joined: Thu Oct 04, 2012 10:56 pm

Re: [Solved] Form button to open url saved in a field?

Postby Koa » Mon May 15, 2017 1:36 am

Thank you! I had some trouble figuring out what you meant by, "The action is :Open document/webpage.", but finally realized that in Control Properties General there was an Action property that I forgot about.
LibreOffice 5.2.5.1 on Linux Jessie 8.6
Koa
 
Posts: 11
Joined: Sun Jan 15, 2017 11:53 pm

Re: [Solved] Form button to open url saved in a field?

Postby johnh009 » Mon Feb 05, 2018 10:45 pm

I appreciate that this post is 'Solved', but I have a question that is linked that hopefully someone could advise me upon.

While the solution provided works for the original problem (open an URL), I would like the same functionality to work for a file (the file path being passed to the Push Button). I've tried with the given basic code (macro), but get the following message:

Code: Select all   Expand viewCollapse view
"/home/path/name" is not an absolute URL that can be passed to an external application to open it.


Must be some specific code within the macro, because when the path to a file is typed into the URL property of the Push Button, the file is opened.
LibreOffice 5.2.6.2 (Build ID:1:5.2.6-1). Linux (Sparkylinux based on Debian) 4.8
johnh009
 
Posts: 7
Joined: Thu Mar 16, 2017 2:00 pm

Re: [Solved] Form button to open url saved in a field?

Postby Villeroy » Mon Feb 05, 2018 11:37 pm

Last weeks
johnh009 wrote:I appreciate that this post is 'Solved', but I have a question that is linked that hopefully someone could advise me upon.

While the solution provided works for the original problem (open an URL), I would like the same functionality to work for a file (the file path being passed to the Push Button). I've tried with the given basic code (macro), but get the following message:

Code: Select all   Expand viewCollapse view
"/home/path/name" is not an absolute URL that can be passed to an external application to open it.


Must be some specific code within the macro, because when the path to a file is typed into the URL property of the Push Button, the file is opened.

Last week's topic: https://forum.openoffice.org/en/forum/v ... 13&t=92140
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 25450
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Form button to open url saved in a field?

Postby johnh009 » Tue Feb 06, 2018 8:27 pm

@Villeroy. Thank you for your prompt response. After following the link you provided and attempting to follow it, it all looked far more complex, with more functionality than I required. So I returned to the original code, had a little read of the Basic manual - the last resort - and discovered the following:

"Since OpenOffice.org is a platform-independent application, it uses URL notation (which is
independent of any operating system), as defined in the Internet Standard RFC 1738 for file
names. Standard file names using this system begin with the prefix file:/// followed by the
local path."

So amending one line of basic,concatenating "file://" to the retrieved pathname string, thus . . .

oEv.source.model.targeturl = "file://"+oTextBox.Text

. . . did the trick. Thanks again.

Having read a little more, the correct way is probably . . .

oEv.source.model.targeturl = ConvertToUrl(oTextBox.Text)
LibreOffice 5.2.6.2 (Build ID:1:5.2.6-1). Linux (Sparkylinux based on Debian) 4.8
johnh009
 
Posts: 7
Joined: Thu Mar 16, 2017 2:00 pm

Re: [Solved] Form button to open url saved in a field?

Postby Villeroy » Tue Feb 06, 2018 10:05 pm

Today I got an inspiration for a slightly more simple version of that macro. I wrapped it into another example database together with an installer (a macro that installs another macro). https://forum.openoffice.org/en/forum/v ... 35#p438435
If you just have one or more columns of fully qualified system paths then you can simply install my new Python macro with one click, draw some button on your own form, change 2 button properties and assign a macro to the "Approve Action" event to "My Macros" > pyDBA > URLButton > FileButton_Approve (this variant includes the conversion from system path to file-URL).
You don't need to program anything at all. Just add the name of the column to the button's "additional info" property.
The new macro does not rely on naming conventions and it does not use form events. Just tell your button about the column name and which macro to call.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 25450
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Forms

Who is online

Users browsing this forum: No registered users and 2 guests