OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

opening a form applying a filter argument

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
Ewald
OOo Advocate
OOo Advocate


Joined: 16 Dec 2005
Posts: 392

PostPosted: Thu Apr 05, 2007 12:17 pm    Post subject: opening a form applying a filter argument Reply with quote

I was just working through the following thread
http://www.oooforum.org/forum/viewtopic.phtml?t=30405
which tells how to open form2 using a command button on form1. Opening form2 works like a charm.
What I would need though is that form2 opens with a filter applied based on an IDField value located on form1. In other words: form1 has a field named IDStudent and I want form2 to be filtered on the IDStudent field using the current IDStudent value in form1 when I hit the command button.
How do I get the value and pass it on to the macro opening form2?
Back to top
View user's profile Send private message
mobi-doc
OOo Enthusiast
OOo Enthusiast


Joined: 30 Jan 2007
Posts: 130
Location: Thessaloniki

PostPosted: Thu Apr 05, 2007 12:51 pm    Post subject: Reply with quote

The following code is on the form1, opens form2 and apply a filter:

Code:

sub main
Dim prop(1) as New com.sun.star.beans.PropertyValue
Dim oF1, oF2, form2
        prop(0).Name="ActiveConnection"
   prop(0).Value=ThisComponent.Parent.DataSource.getConnection("","")
   prop(1).Name="OpenMode"
   prop(1).Value="open"
        form2=ThisComponent.Parent.FormDocuments.loadComponentFromURL _
                ("form2","_blank",0,prop())
   oF2=form2.DrawPage.Forms(0)
        oF1=ThisComponent.DrawPage.Forms(0)
   oF2.ApplyFilter=True
   oF2.Filter="filtered_field = " & oF1.getString(...)
end sub

[/code]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ewald
OOo Advocate
OOo Advocate


Joined: 16 Dec 2005
Posts: 392

PostPosted: Fri Apr 06, 2007 3:01 am    Post subject: Reply with quote

Tanks mobi-doc. The code works with one little caveat: how do I get the filter string from the control IDStudent on form1?

if I enter .....oF1.getString(IDStudent) or oF1.getString("IDStudent") I keep getting an error message saying SQL Status:
HY000
Error code: 1000
SELECT * FROM "tbStudent" WHERE filtered_field =
syntax error, unexpected $end
Back to top
View user's profile Send private message
mobi-doc
OOo Enthusiast
OOo Enthusiast


Joined: 30 Jan 2007
Posts: 130
Location: Thessaloniki

PostPosted: Fri Apr 06, 2007 8:20 am    Post subject: Reply with quote

getString accepts an integer argument. For example if you want to get the 1st field of your result set or form then give a 1.

It is better to install OOo SDK only to have local access to IDL library to see each method in detail. And the XRay tool would be useful too!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ewald
OOo Advocate
OOo Advocate


Joined: 16 Dec 2005
Posts: 392

PostPosted: Fri Apr 06, 2007 12:46 pm    Post subject: Reply with quote

Thanks mobi-doc. I did get the SDK and the x-ray tool. I also installed OOo2.2 (was on 2.1 so far).
Now your code gives a syntax error in the following line:
prop(0).Name="ActiveConnection"

When using OOo2.1 the code works (I have OOo 2 on a different computer, both running XP).
Another question: how do I find out about the order of the controls on a form?
Does this code also work, when the filter argument is on a subform?
Back to top
View user's profile Send private message
mobi-doc
OOo Enthusiast
OOo Enthusiast


Joined: 30 Jan 2007
Posts: 130
Location: Thessaloniki

PostPosted: Fri Apr 06, 2007 1:00 pm    Post subject: Reply with quote

Code:

form1=ThisComponent.DrawPage.Forms(0)

always gives the 1st (root) form. For subforms you must get them by their name
Code:

form2=form1.GetByName("SubForm")


You can filter any form you want.

I don't know why your code doesn't work on 2.2. Please give more details.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ewald
OOo Advocate
OOo Advocate


Joined: 16 Dec 2005
Posts: 392

PostPosted: Fri Apr 06, 2007 1:11 pm    Post subject: Reply with quote

The Details are:

I installed OOo2.2 on my Desktop, installed SDK and x-ray tools.
Then I copied the database I am currently putting together on the desktop.
When I hit the button having your code from above, I get the error message:

"Basic Syntax Error", the following line is marked:
prop(0).Name="ActiveConnection"

The very same code gives the desired funtionality in the very same database running on my laptop which has OOo2.1 installed. Both machines are running XP.
Back to top
View user's profile Send private message
Ewald
OOo Advocate
OOo Advocate


Joined: 16 Dec 2005
Posts: 392

PostPosted: Fri Apr 06, 2007 1:32 pm    Post subject: Reply with quote

I found out about the Basic syntax error:

When I place the macro to open form2 (see above) under My Macros>Standard I get the behaviour described above.
When I place the very same Macro under the Standard macros of form1 then it works just fine.
Seems very strange to me but then all I have learned so far is MSAccess and visual basic which doesn't seem to be helpful at all when working with OOo.

Thank's a bunch, I'll keep asking those questions as they come up.
Back to top
View user's profile Send private message
mobi-doc
OOo Enthusiast
OOo Enthusiast


Joined: 30 Jan 2007
Posts: 130
Location: Thessaloniki

PostPosted: Fri Apr 06, 2007 11:07 pm    Post subject: Reply with quote

The code is designed to run from the form document itself. That's why it doesn't run when installed on MyMacros library container.

ThisComponent is a BASIC statement that represents the model of the component the currently running code is resided. I don't know what ThisComponent represents when is placed on code residing on MyMacros library container.

There are no so much differences between StarBASIC and VBA. The real differences are on component models which is UNO for OpenOffice and (whater is for this month for microsoft windows, I forgot to check Smile)

When I decided to work with Base, the first impression was dissapointing. But with step by step learning I built something useful. So don't be dissapointed.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group