Macro to refresh open but not current form

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
considerlocal
Posts: 5
Joined: Fri Jun 29, 2012 2:02 pm

Macro to refresh open but not current form

Post by considerlocal »

Hi,
I currently have a macro which when run from one form opens another form and inserts a new record into it. I now need this macro to go to the newly opened form and go to the new record created (ie. the last record). One way to do this is to place a new macro to run on the launch of the newly opened form to 'go to last record'. This works fine, unless the form is already open. If already open, it does not refresh and does not go to the newly created record.
The record macro function provides the following:

Code: Select all

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:Refresh", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:LastRecord", "", 0, Array())
If I tag this on to the macro from the first form it simply refreshes the first form, not the form I want to refresh.
If you can understand this issue and can help, much appreciated.
Thanks
Last edited by RoryOF on Tue Jul 03, 2012 6:30 pm, edited 1 time in total.
Reason: If posting Code, please use the Full Editor and press the Code button. This makes postings more readable.
Andy Keehner
Consider Local
Open Office 3.4 - Windows 7
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Macro to refresh open but not current form

Post by RPG »

Hello

The button must be in the form what must be refreshed.

Code: Select all

sub
oform.refresh
oform.last
end
Romke
 Edit: Maybe you need reload instead of refresh 
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
considerlocal
Posts: 5
Joined: Fri Jun 29, 2012 2:02 pm

Re: Macro to refresh open but not current form

Post by considerlocal »

The button must be in the form what must be refreshed.
I realise this, and this is my exact problem so hoping someone has a way round it.
Edit: Maybe you need reload in stead off refresh
Does this not pose same problem?
Andy Keehner
Consider Local
Open Office 3.4 - Windows 7
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Macro to refresh open but not current form

Post by RPG »

Hello

Your question give no information for a more detailed answered. So I think forget macros or start study.
http://wiki.services.openoffice.org/wik ... ASIC_Guide

Or study the examples of this forum.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: Macro to refresh open but not current form

Post by kingfisher »

It may help to have a sample of a document illustrating the issue. I can't even tell from this thread which application is involved.
Apache OpenOffice 4.1.9 on Linux
JPL
Volunteer
Posts: 130
Joined: Fri Mar 30, 2012 3:14 pm

Re: Macro to refresh open but not current form

Post by JPL »

Hello,

I indeed does not exactly understand what you want to get.

However, if I can make a suggestion:
- download the Access2Base extension and install it.
- depending on your scenario execute one of next code snippets from the appropriate macro trigger (button, ...)

1. The 2 forms are open and you want from the 1st form jump to the last record of the 2nd one:

Code: Select all

Const acForm = 2
Const acLast = 3
      SelectObject(acForm, "Form2")
      GotoRecord(,, acLast)
2. Only 1 form is open

Code: Select all

Dim ofFormB As Object
Const acLast = 3
      ofFormB = OpenForm("Form2")
      setFocus(ofFormB)
      GotoRecord(,, acLast)
3. The 2 forms are open but, for any reason (below simulated by a SQL "Insert" statement), the 2nd form needs to be updated:

Code: Select all

Dim ofFormB As Object
Const acLast = 3
      ofFormB = Forms("Form2")
      RunSQL("INSERT ...")      '     which should have as effect to build a new record in Form2 in the last position
      Requery(ofFormB)
      setFocus(ofFormB)
      GotoRecord(,, acLast)
4. A variant of #3: the INSERT statement depends on values stored in one of the controls of form1:

Code: Select all

Dim ofFormA As Object, ofFormB As Object, sSQL As String, ocControl As Control
Const acLast = 3
      ofFormA = Forms("Form1")
      ofFormB = Forms("Form2")
      ocControl = Controls(ofFormA, "myControl")
      sSQL = "INSERT etc. WHERE ... = '" & ocControl.Value & "'"
      RunSQL(sSQL)
      setFocus(ofFormB)
      Requery(ofFormB)
      GotoRecord(,, acLast)
Hoping this could help.
Kubuntu 22.04 / LibO 7.5
Access2Base (LibO).
BaseDocumenter extension (LibO)
ScriptForge (LibO)
Documentation on https://help.libreoffice.org/latest/en- ... bPAR=BASIC
Post Reply