Open specific Database Record in Form with a Macro

Creating and using forms
Post Reply
openk
Posts: 1
Joined: Mon Jan 11, 2016 2:45 am

Open specific Database Record in Form with a Macro

Post by openk »

I have a strange problem with opening another writer-document with a Basic-Makro.

Here's what I want to do:

There's a MySQL-database that is accessed via JDBC-Connector. The Frontent is done in OpenOffice 3.2.1 (WinXP) with several Forms that are stored as single Writer-Documents. To swith between forms, I use oDocFrame.loadComponentFromURL( cUrl, "_self", 0, args() ) and it works without problems.

Now I want to change a form and open a specific record in the other form.

I do it with the following makros:

Form1

Code: Select all

oform=ThisComponent.drawpage.forms.getbyname("MainForm")
if( oform.filter <> "" OR oform.ApplyFilter=TRUE ) then
        oform.filter= ""
        oform.ApplyFilter=FALSE
end if

Dim args(2) As New com.sun.star.beans.PropertyValue
args(0).Name = "ActiveConnection"
args(0).Value = getConnectionTC
args(1).Name = "OpenMode"
args(1).Value = "open"
args(2).Name = "MacroExecutionMode"
args(2).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
oDoc = ThisComponent
oDocCtrl = oDoc.getCurrentController()
oDocFrame = oDocCtrl.getFrame()
cUrl = ConvertToURL( "FORM2" )
oDocument=oDocFrame.loadComponentFromURL( cUrl, "_self", 0, args() )
sScriptURI = "vnd.sun.star.script:FORM2.btnsJur.JurPkFilt.InsertValues?language=Basic&location=document" ' My Filter-Makro in Form 2
oScriptProvider = oDocument.getScriptProvider()
oScript = oScriptProvider.getScript(sScriptURI)
oScript.invoke(Array(Key_To_Filter_For), Array(), Array() )

Form2

Code: Select all

Sub JurPkFilt( idx AS INTEGER )
    oform=ThisComponent.drawpage.forms.getbyname("MainForm")
    oform.filter= "( `buz`.`FORM2`.`pkJurPersonNr` = " & idx & ")"
    oform.ApplyFilter=TRUE
    oform.reload
END SUB
The problem is that it works -- but only most of the time. Sometimes Openoffice just freezes when I try to change forms. It's hard to figure out when it freezes. I think there is a correlation towards the further use of a filter in Form1. But I'm not sure, as there is no explicit way to reproduce the freeze :(

Any Ideas what goes wrong here?

If not: Any ideas how I can archieve my goal -- open FORM2 with a macro in FORM1 and tell FORM2 to select a specific record -- in another way?
Openoffice 3.2.1 on Windows XP and LibreOffice 3.5 on Debian Wheezy
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Open specific Database Record in Form with a Macro

Post by MTP »

It's probably worth trying to combine the two macros into one like this:

Code: Select all

oform=ThisComponent.drawpage.forms.getbyname("MainForm")
if( oform.filter <> "" OR oform.ApplyFilter=TRUE ) then
        oform.filter= ""
        oform.ApplyFilter=FALSE
end if

Dim args(1) As New com.sun.star.beans.PropertyValue
args(0).Name = "ActiveConnection"
args(0).Value = getConnectionTC
args(1).Name = "OpenMode"
args(1).Value = "open"
oDoc = ThisComponent
oDocCtrl = oDoc.getCurrentController()
oDocFrame = oDocCtrl.getFrame()
cUrl = ConvertToURL( "FORM2" )
oDocument=oDocFrame.loadComponentFromURL( cUrl, "_self", 0, args() )

oform2=oDocument.drawpage.forms.getbyname("MainForm")
oform2.filter= "( `buz`.`FORM2`.`pkJurPersonNr` = " & Key_To_Filter_For & ")"
oform2.ApplyFilter=TRUE
oform2.reload
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
Post Reply