[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 475 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 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2099
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


Return to Forms

Who is online

Users browsing this forum: No registered users and 3 guests