Macro to refresh open but not current form

Creating a macro - Writing a Script - Using the API

Macro to refresh open but not current form

Postby considerlocal » Tue Jul 03, 2012 6:13 pm

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   Expand viewCollapse view
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
considerlocal
 
Posts: 5
Joined: Fri Jun 29, 2012 2:02 pm

Re: Macro to refresh open but not current form

Postby RPG » Tue Jul 03, 2012 6:31 pm

Hello

The button must be in the form what must be refreshed.
Code: Select all   Expand viewCollapse view
sub
oform.refresh
oform.last
end


Romke

 Edit: Maybe you need reload instead of refresh 
openSuse version of LibreOffice 4.1.5.3 stable on openSUSE 12.2
RPG
Volunteer
 
Posts: 1548
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Macro to refresh open but not current form

Postby considerlocal » Tue Jul 03, 2012 11:17 pm

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
considerlocal
 
Posts: 5
Joined: Fri Jun 29, 2012 2:02 pm

Re: Macro to refresh open but not current form

Postby RPG » Tue Jul 03, 2012 11:48 pm

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
openSuse version of LibreOffice 4.1.5.3 stable on openSUSE 12.2
RPG
Volunteer
 
Posts: 1548
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Macro to refresh open but not current form

Postby kingfisher » Wed Jul 04, 2012 5:40 am

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.
OpenOffice 3.3 on PCLinuxOS. There are 3 kinds of people: those who can count and those who can't.
User avatar
kingfisher
Volunteer
 
Posts: 1860
Joined: Tue Nov 20, 2007 10:53 am

Re: Macro to refresh open but not current form

Postby JPL » Fri Jul 06, 2012 6:06 pm

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   Expand viewCollapse view
Const acForm = 2
Const acLast = 3
      SelectObject(acForm, "Form2")
      GotoRecord(,, acLast)

2. Only 1 form is open
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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   Expand viewCollapse view
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.
Windows 7 / OOo 4.0 / LibO 4.2
Ubuntu 13.10 / LibO 4.2
The Access2Base extension for AOO/LibO Base can be downloaded from the AOO/LibO extension centers. It is embedded in LibreOffice 4.2
Its documentation is on http://www.access2base.com.
JPL
 
Posts: 42
Joined: Fri Mar 30, 2012 3:14 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests