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

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

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.

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.

Ratslinger, you’ve shown two differing and separate text blocks, both with the same Sub GetURL value. 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/site/

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

(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/site/$STID” 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/site/f2882

@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.

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 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.