Ask Your Question
0

What event is triggered when I click on a base form? (solved)

asked 2018-11-16 21:53:35 +0200

Pansmanser gravatar image

updated 2018-11-18 19:04:48 +0200

I would like to use a macro to auto-filter a base form when I click the mouse in the form. eg click on 'X' in column 'code' and the form will auto-filter to select all records with 'X' in 'Code'. This makes it possible for less skilled operators to work the form. My question is whether an event is triggered when I click on the form and if so what event? Without that, I don't think it can be done.

Edit: I have realised that there is an event associated with the grid, while I was looking for a column event. Can the grid event track down the column and row?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2018-11-16 23:59:06 +0200

Ratslinger gravatar image

updated 2018-11-17 02:07:59 +0200

Hello,

Attach the following:

Sub GetGrid(oEvent)
    Dim oForm As Object
    Dim oColumn As Object
    Dim sValue as String
    Dim sFilter as String
    Dim sColumnName as String
    Dim iColumn as Integer
    If oEvent.Buttons = 1 and oEvent.Modifiers = 2 Then
        oForm = ThisComponent.Drawpage.Forms.getByName("YOUR_FORM_NAME")
        iColumn = oEvent.Source.CurrentColumnPosition
        oColumn = oForm.Columns.getByIndex(iColumn)
        sColumnName = oColumn.Name
        sFilter = "(" & sColumnName & " = '" & oColumn.String & "')"
        oForm.Filter = sFilter
        oForm.reload()
    End If
End Sub

to the Mouse button released event of the grid. To activate, hold down Ctrl key when left mouse clicking a cell in the grid. The selected value will be used for the filtering.

To clear the filtering, place a button on the form attached to this macro:

Sub ClearFilter
    Dim oForm As Object
    oForm = ThisComponent.Drawpage.Forms.getByName("YOUR_FORM_NAME")
    oForm.Filter = ""
    oForm.reload()
End Sub

Edit:

Please note that this wasn't tested against all field types. Has worked for integer, varchar, decimal, and boolean fields. The Ctrl key will not work if the column is a list box ( combo box seems to work). If you want to use the list box possibly change from Ctrl to Alt key (modifier = 4).

I understand you wanting this for those users not able to cope with the normal filtering, and the added key is more than just a click but just clicking will be a problem anytime a cell is selected.

edit flag offensive delete link more

Comments

Brilliant as usual, Ratslinger. Thank you. And you're quite right about preferring Ctrl-click. I had to make a couple of mods. I had to change to oForm = oEvent.Source,Model.Parent and I had to add an apparently arbitrary 11 to iColumn. The reason for the latter is that not all the fields in the underlying query are displayed, and while CurrentPosition returns the position in the table, getByIndex looks up the query. I'm just saying this in case anyone else is looking for it.

Pansmanser gravatar imagePansmanser ( 2018-11-18 19:04:28 +0200 )edit
0

answered 2018-11-17 02:01:07 +0200

EasyTrieve gravatar image

updated 2018-11-19 05:10:08 +0200

[updated below]

@Pansmanser, this isn't an answer, but a comment to help clarify what you want to do.

How does what you want to do relate to the already existing filter feature, that to me, appears to do the same thing?

For example, start with this table (you may need to zoom your browser in to see it more clearly):

image description

In it under the Major Category click on 'Home' on record with ID of 3 to select it.

Next click on this icon image description which sets up a filter so that now the only records shown are those with Major Category = Home.

image description

Undo it with image description


Ok, then by going to Menu | Customization I was able to drill down to this to find the name of the function is AutoFilter. Now the next step is to figure out how to call it with a macro.

image description

But... I don't know how to do that. Am searching...

Ok, can't find how to do that.

So, instead need to be able to get the value of the current field, then put that into an appropriate filter.

Do you know how to do that already? It's a matter of starting MRI when the field is clicked, then drilling down to find the text in the field, then using that to create the sql to put into the form's (table's) filter.

This somewhat depends on what type of control you want to be able to click on. Simple text boxes are fairly easy, pull down boxes (combo or list) are harder.

edit flag offensive delete link more

Comments

Thanks, EasyTrieve, but I want to do just that but a single click with a macro.

Pansmanser gravatar imagePansmanser ( 2018-11-18 18:28:56 +0200 )edit
1

@EasyTrieve
Yes you could do exactly this with the autofilter. You can execute autofilter from a macro also, but not by calling a function.

Instead you dispatch an event into the application event handler named .uno.Autofilter.

This literally makes the application respond as if the user clicked on the autofilter button.

DrewJensen gravatar imageDrewJensen ( 2018-11-19 13:52:21 +0200 )edit

@DrewJensen +1, cool, thanks.

EasyTrieve gravatar imageEasyTrieve ( 2018-11-20 02:39:48 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-11-16 21:53:35 +0200

Seen: 160 times

Last updated: Nov 19 '18