Ask Your Question

basic macro get field data from database form

asked 2018-11-17 23:48:19 +0100

Carrbigdog gravatar image

updated 2018-11-27 20:28:03 +0100

EasyTrieve gravatar image

On a Windows 7 system with Version: (x64). I wish to extract the file link data from a LO Base form field and use it to open an image viewer in a new window so the image can be rotated and or zoomed.
I will associate the macro with a button on the form. I can get the viewer to open with a hard coded parameter string, but cannot figure out how to get the link to the image into the variable named MyParam. Any suggestions, examples or links to instructions would be greatly appreciated.

----------Macro as it stands copied from various sources -

Sub ImageView

Dim MyWindowstyle As Integer
Dim MyParam As String
Dim MyPathname As String
Dim MyBsync As Boolean
MyPathname="C:\Program Files (x86)\IrfanView\i_view32.exe"
REM  MyParam="E:\User\Devlpmnt\DataProject\Images\Volume 58 021.jpg"
MyWindowstyle = 1

Shell(MyPathname, MyWindowstyle, MyParam, MyBSync)

End Sub

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-11-18 05:42:06 +0100

Ratslinger gravatar image


Macros are a bit more than just saying move A to B. Even something to an experienced macro coder as simple as what you are looking for is difficult to explain with the limited info you have provided. Here is what can be said.

First you need to access the internal form. Now this is a bunch of steps all grouped together:

oForm = ThisComponent.Drawpage.Forms.getByName("YOUR_INTERNAL_FORM_NAME")        'Get Form

Now it depends on the control as to how the information is accessed. You don't specify the type of control so here are a couple of scenarios. If the control is a Text box, then you can retrieve the data:

oField = oForm.getByName("MY_CONTROLS_NAME")      'Get control tied to wanted info'
MyParam = oField.Text                             'Get text from control'

If, however, the control is an image control, it is easiest to access the data straight from the table data in the form:

  oColumns = oForm.getColumns()
  oDataColumn = oColumns.getByName("TABLE_DATA_NAME")
  MyParam = oDataColumn.getString()

This is about all that can be given without specific info provided on your setup.

edit flag offensive delete link more


I like using the oField.getCurrentValue() method, as it works for most of the standard field types including text, numeric, currency, checkbox, list box, etc. I'm not sure if .text works for list boxes. I haven't had to deal with images yet, so that's cool to see that detail.

PhLo gravatar imagePhLo ( 2018-11-18 06:14:30 +0100 )edit

answered 2018-11-20 07:26:01 +0100

Carrbigdog gravatar image

Thanks for all the help.

This macro is intended to be used with a BASE Form. I added the statement oForm = ThisComponent.Drawpage.Forms.getByName("ImageEntry") but got the error "Property or Method not Found: Drawpage

  • changed it to oForm = ThisComponent.FormDocuments.getByName("ImageEntry")

this appears to work, but the following statement oField = oForm.getByName("ImageLink") 'Get control tied to wanted info'

got the Error Property or Method Not found: getByName

Not sure what I am doing wrong. All errors are from trying run from the Tools-Organize Macros - LibreOffice Basic

edit flag offensive delete link more


Code is different when executed from the IDE vs the Form itself. Also, it appears you are using the external form name. This should be the internal form name which is usually by default 'Main' or 'MainForm' but can be anything you set it to.

The code in the answer deals with the internal form name (as noted) and that is the reason for the error.

Edit the form. On the Form Design toolbar is the Form Navigator icon. select that & you will see internal for name(s) and control name(s).

Ratslinger gravatar imageRatslinger ( 2018-11-20 17:14:57 +0100 )edit

Thanks, This worked perfectly. Now how do I accept this as a solution?

Carrbigdog gravatar imageCarrbigdog ( 2018-11-24 23:20:56 +0100 )edit

Glad all is well. You already clicked on the check mark which signifies an accepted answer.

Ratslinger gravatar imageRatslinger ( 2018-11-24 23:25:44 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-11-17 23:48:19 +0100

Seen: 385 times

Last updated: Nov 27 '18