Ask Your Question
0

How can a value be passed to URL in LO Base Form

asked 2019-04-20 22:04:16 +0200

kbellis gravatar image

image description

RE: LO Base, Forms, Push Button Action, v6.2.3.2, Windows 10 Pro 64-bit

From a form with a Push Button whose Action is to Open document/web page, how can a field value be passed to the URL; e.g.

table:field: STID
URL: https://weather.gladstonefamily.net/site/$STID

Thanks for any reply!

Kind regards,

Kelly

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-04-20 23:46:12 +0200

Ratslinger gravatar image

Hello,

You do this with a macro:

Sub GetURL
    Dim oForm As Object
    Dim oButton As Object
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
    oButton = oForm.getByName("PushButton2")
    oButton.TargetUrl = "https://weather.gladstonefamily.net/site/$STID"
end sub

This macro is based upon the internal form name of MainForm and the button name of PushButton2.

Executing this macro will move the data into the proper field. Then when the button is pressed, the URL is retrieved.

Now this can be gotten from a field in a record and upon every record change the push button data is made ready:

Sub GetURL
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
    DocCtl = ThisComponent.getCurrentController()
    oField = oForm.getByName("txtURL")
    oButton = oForm.getByName("PushButton2")
    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.

edit flag offensive delete link more

Comments

That looks very encouraging - thank you so much Ratslinger! I must first dive down this new macro-related rabbit hole before seeing it work and maybe even understanding how. My use of $STID was a made up name for this variable; it's not a literal value, just in case I have mis-written something or have been unclear.

kbellis gravatar imagekbellis ( 2019-04-21 14:58:34 +0200 )edit

Ratslinger, you've shown two differing and separate text blocks, both with the same Sub GetURLvalue. Neither one of them are calling for the STID's field value to be passed to the tailend of the URL https://weather.gladstonefamily.net/s...

LO Base, v6.2.3.2, Embedded database, Firebird Embedded

database name: Stations.odb table name: Stations form name: Stations Push Button name: btnCWOPInfo

Properties: Push Button, Events, there is no After record change event listed.

Tools, Macros, Organize Macros, LibreOffice Basic..., LibreOffice Basic Macros, selected/ highlighted Stations.odb in left panel, click New, New Module name: `passSTIDtoURL' , OK, in right side panel:

REM  *****  BASIC  *****

Sub GetURL
    Dim oForm As Object
    Dim oButton As Object
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
    oButton = oForm.getByName("PushButton2")
    oButton.TargetUrl = "https://weather.gladstonefamily.net/site/$STID"
end sub
kbellis gravatar imagekbellis ( 2019-04-21 18:20:17 +0200 )edit

(continued after reaching character limit) Saved. Stations.odb Standard passSTIDtoURL Closed [Stations.odb].Standard

editing form, Push Button Properties, Events, Execute action, Macro, Macro Selector, Library passSTIDtoURL, Macro Name, GetURL, OK, OK

Then in Push Button Properties,General tab, URL value appears "https://weather.gladstonefamily.net/s..." Same as I had to begin with at top of this post.

What I was asking about was how can the field value for STID be passed to the tail end of the URL? So for example a record with STID=f2882 would then translate to a URL of "https://weather.gladstonefamily.net/s..."

kbellis gravatar imagekbellis ( 2019-04-21 18:33:24 +0200 )edit

@kbellis It appears you are not quite familiar with Base. You probably should review more of the documentation.

Know that there is the Document form name which is the name on the Base Forms section and then there is the internal Form name which is used in macros. You can have many forms, sub forms, and sub sub forms in a form.

Also, the two routines were explained in the answer. The first simple uses a literal moved into the push button URL field. The second elaborates on the first by getting the data from text field txtURL and moving that into the button field. It does this when you set the INTERNAL form event After record change not a button event.

Ratslinger gravatar imageRatslinger ( 2019-04-21 18:43:44 +0200 )edit

You resulting sub is something such as:

Sub GetURL
Rem using internal form name - yours may differ - verify
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
    DocCtl = ThisComponent.getCurrentController()
Rem based on your info
    oField = oForm.getByName("STID")
Rem based on your info
    oButton = oForm.getByName("btnCWOPInfo")
    CtlView = DocCtl.GetControl(oField)
    sURL = "https://weather.gladstonefamily.net/site/" & CtlView.Text
    oButton.TargetUrl = sURL
end sub
Ratslinger gravatar imageRatslinger ( 2019-04-21 18:52:38 +0200 )edit

@Ratslinger Yes, you are correct, there is much for me to learn as all things LibreOffice, and Base especially are new to me. Thank you for your kind help.

kbellis gravatar imagekbellis ( 2019-04-21 19:24:48 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-04-20 22:04:16 +0200

Seen: 33 times

Last updated: Apr 20