Refresh and go to current record

Discuss the database features
Post Reply
Szaibot
Posts: 3
Joined: Mon Aug 20, 2018 3:00 pm

Refresh and go to current record

Post by Szaibot »

Hi,

I'm creating small database with few information field and categories on listbox (in main form).
Next to listbox I'm trying to add button which will be linked to "add category form" ( with field: id, category name and one buton: save and return). At this moment it will popup new window where I can add new category and return, but it will not display it. I was trying to figure it out by myself… But refresh button will refresh but also jump to first record … is there way to make it work? I was trying to recreate few ideas from forum but they don't work.
OpenOffice 4.1.5 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Refresh and go to current record

Post by Villeroy »

There are two refresh buttons on the navigator toolbar. The second one becomes enabled when a combo or list box is focussed. It refreshes the content of the control without affecting the state of the form.
Last edited by Villeroy on Tue Aug 21, 2018 12:50 pm, edited 2 times in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Szaibot
Posts: 3
Joined: Mon Aug 20, 2018 3:00 pm

Re: Refresh and go to current record

Post by Szaibot »

Villeroy wrote:There are two refresh buttons on the navigator toolbar. The second one becomes enabled when a combo or list box is focussed. It refreshes the content of the control without affecting the state of the form.
Yes I know, but with i.e. 20 records after refresh it will jump to first record, and you will need to go back to last edited record manualy. I was trying with macro to somehow "remember" record numer, refresh form, and go to remembered record but with no luck ;/


aaa You were talking about second one :D It's working : :) Thank you!
OpenOffice 4.1.5 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Refresh and go to current record

Post by Villeroy »

The pop-up-other-window kind of approach is not viable with Base forms unless you are a very routined programmer. Simply use a small input form for new records in the same form hierarchy. Then refresh the form control.
You can use a custom toolbar button with the buttons you need.
You can use a toolbar control where you can hide sections.
You can even use a push button with property "Open Document or URL" and the URL .uno:RefreshFormControl which fails silently when no refreshable control is focussed
You can use one of the simple macros on this forum which operate within the same hierarchy of forms.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Refresh and go to current record

Post by UnklDonald418 »

Maybe this might help

Code: Select all

Sub reloadForm(oEvent As Object)
  Dim oForm As Object
  Dim CurrRow As Integer
  oForm=oEvent.Source.Model.Parent
  CurrRow=oForm.Row
  oForm.reload()
  oForm.absolute(CurrRow)
End Sub
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Refresh and go to current record

Post by Villeroy »

Huh? Does that really work?

Indeed, it does!
(unless the mere row number changes due to the reload process)

Base does not support bookmarking as MS Access does:
bm = form.Bookmark
form.reload()
form.gotoBookmark(bm)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Refresh and go to current record

Post by UnklDonald418 »

Thanks Villeroy, the following also appears to work

Code: Select all

Sub reloadForm(oEvent As Object)
  Dim oForm As Object
  Dim Bmk
  oForm=oEvent.Source.Model.Parent
  
  Bmk = oForm.getBookmark()
  oForm.reload()
  oForm.moveToBookmark(Bmk)
End Sub
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Szaibot
Posts: 3
Joined: Mon Aug 20, 2018 3:00 pm

Re: Refresh and go to current record

Post by Szaibot »

Thanks, for response, maybe it's bad idea to use record macro option, but in this case it's working. Is it correct to use such a macro?

sub refresh_small
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:RefreshFormControl", "", 0, Array())


end sub
I've connected it to event "push button" action
OpenOffice 4.1.5 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Refresh and go to current record

Post by Villeroy »

Szaibot wrote:Thanks, for response, maybe it's bad idea to use record macro option, but in this case it's working. Is it correct to use such a macro?

sub refresh_small
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:RefreshFormControl", "", 0, Array())


end sub
I've connected it to event "push button" action
This is exactly the same as an URL button with URL .uno:RefreshFormControl instead of a macro
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Refresh and go to current record

Post by UnklDonald418 »

Is it correct to use such a macro?
There is nothing wrong with using a recorded macro, as long as it does what you need it to do.
Recorded macros use Dispatcher commands, rather than dealing directly with the OpenOffice API so there are some limitations and Dispatcher commands are poorly documented. Then and there is the issue that the macro recorder only works in the Writer and Calc modules, but not Base.
Either one of the two Basic macros presented earlier should work when invoked by the Appove action event of a Push Button control on the form that needs to be refreshed. The Action property on the General tab of the Properties: Push Button dialog should be set to None. They both refresh the form and return to the row number where the button was pressed.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply