# basic macro get field data from database form

On a Windows 7 system with Version: 6.0.5.2 (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
MyBSync=true

Shell(MyPathname, MyWindowstyle, MyParam, MyBSync)


End Sub

edit retag close merge delete

Sort by » oldest newest most voted

Hello,

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.

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.

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

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'

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

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

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

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

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