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

[SOLVED] Filtering Macro Works Intermittently

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
cazbym
Power User
Power User


Joined: 16 Mar 2009
Posts: 63

PostPosted: Wed Apr 11, 2012 7:12 am    Post subject: [SOLVED] Filtering Macro Works Intermittently Reply with quote

Hi,

I have several standalone forms connected to my database, but I will mention only two in particular.

One is based on a table "Customers" and the other is based on a table "Projects". There is a 1 to many relationship.

I also have a small macro attached to a push button on the Customers form which opens and applies a filter on the Projects form.

On the Projects form I have several macros all attached to push buttons which open and apply filters to several other forms – all of which work very well.

Now if I open the Projects form and select and push any of the push buttons, they work as expected.

However, if I open the Projects form from a push button execute event on the Customers form, ie a filtered version of the form, none of the buttons work, even though it is exactly the same form.

I assumed that this must be because there is already a filter applied. But if I open the Projects form without filtering and then apply a filter manually, the push buttons still work as expected. Can anyone point to what can be wrong with this. It seems the macro needs more than it has....I think.

Macros for anybody interested:

Macro on Customers form (if this is used, then the macros connected to the opening Projects form no longer function)

Code:

Sub   Link_Project_By_CustomerID (oEvent As Object)
   oForm = oEvent.Source.Model.Parent
   iID=oForm.getByName("TableControl").getByName("listDesc").BoundField.getInt
   cFile = "C:\Users\Public\Documents\FORMS\Projects.odt"
   cUrl = ConvertToURL( cFile )
   oForm2 = StarDesktop.loadComponentFromURL( cUrl, "_blank", 0, Array() )
   oForm3 = oForm2.DrawPage.Forms.getByName ("MainForm")
   oForm3.Filter="( ""Projects"".""CustomerID"" =  " & iID & " )"
   oForm3.ApplyFilter=True
   oForm3.Reload()
End Sub


Macro on Projects form (one of many which only work if form is opened and/or filtered manually.)

Code:

Sub   Link_Documents_By_ProjectCode (oEvent As Object)
   oForm = oEvent.Source.Model.Parent
   iID=oForm.getByName("TableControl").getByName("ProjectCode").text
   cFile = "C:\Users\Public\Documents\FORMS\Documents.odt"
   cUrl = ConvertToURL( cFile )
   oForm2 = StarDesktop.loadComponentFromURL( cUrl, "_blank", 0, Array() )
   oForm3 = oForm2.DrawPage.Forms.getByName ("MainForm")
   oForm3.Filter="( ""Documents"".""ProjectCode"" ='" & iID & "')"
   oForm3.ApplyFilter=True
   oForm3.Reload()
End Sub


Last edited by cazbym on Thu Apr 12, 2012 7:25 am; edited 1 time in total
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Wed Apr 11, 2012 8:23 am    Post subject: Reply with quote

Hello

Quote:
However, if I open the Projects form from a push button execute event on the Customers form, ie a filtered version of the form, none of the buttons work, even though it is exactly the same form.

The quote line can means different things.
I think you overwrite an already existing filter with your new filter data.

It seems to me you want to expand the old filter and not overwrite the filter as you do now.

Romke
_________________
OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum
Back to top
View user's profile Send private message
cazbym
Power User
Power User


Joined: 16 Mar 2009
Posts: 63

PostPosted: Wed Apr 11, 2012 9:31 am    Post subject: Reply with quote

It shouldn't really matter - I think. One filter is on the Projects form, but I am not trying to apply another filter to the Projects form, but pull a ProjectID from the filtered list. I always have a button to print the filter to screen, and this also does not work on the automatically filtered Projects form, but does if the Projects form is opened manually AND filtered manually to match the original filter. Confused

If I open the Projects form filtered by the macro on the Customers form, none of the push button macros work. If I remove the filter on the Projects form, refresh the page and apply the same filter that the macro from the Customers form applied, manually, the push buttons all work again.

In other words I can pull the information I require and open the Documents form if I apply all filters manually, but if I try to pull the information from the macro filtered form nothing happens at all.

I hope this all makes sense.

Just to recap

Customers form - Select one Record - Push Button to open and apply CustomerID filter on Projects form.

Projects form - opened and filtered by CustomerID - displays n records.

Select required record - Push Button to open and apply ProjectID filter to Documents form.
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Wed Apr 11, 2012 10:43 am    Post subject: Reply with quote

Hello

It is real difficult to find bugs in code when you see only a little. Maybe there is no real bug in your code and there is something wrong in the order of how to open and close other parts(components) of your documents.

This question does me remember to an other question. the new data was not stored to a database when the database was closed. The problem was in the way the database was opened and not really in the code. Before we understand how the database was opened and there was the problem we did 10 posts.

Do you have open a dialog? A gues!

I have no idea on this moment

Romke
_________________
OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum
Back to top
View user's profile Send private message
cazbym
Power User
Power User


Joined: 16 Mar 2009
Posts: 63

PostPosted: Thu Apr 12, 2012 2:42 am    Post subject: Reply with quote

Link to my database and standalone forms. I am using File Mode HSQLDB (single user) – sorry cannot remember how to remake as an embedded version.

http://www.mediafire.com/?ityecbk4b3di7

If either of the standalone forms are opened independently and the push buttons activated, the macros will work.

However, if I open the Customers.odt and use the push button to open the Projects.odt (filtered by Analysis4) the macros to open Documents.odt no longer work.

If I manually open Projects.odt and manually apply the same filter on Analysis4, the macro DOES work.

Any help greatly appreciated.
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Thu Apr 12, 2012 4:58 am    Post subject: Reply with quote

Hello

When I insert a little sub for only beep, I get a security warning. I can not find the reason for this warning and it is only in mdprojects.

I have test only two files mdCustomers and mdreports. This warning I get only when I try to run it in the IDE and is silent when I activated it with a button.

Romke
_________________
OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum
Back to top
View user's profile Send private message
cazbym
Power User
Power User


Joined: 16 Mar 2009
Posts: 63

PostPosted: Thu Apr 12, 2012 6:01 am    Post subject: Reply with quote

RPG wrote:
Hello

When I insert a little sub for only beep, I get a security warning. I can not find the reason for this warning and it is only in mdprojects.

I have test only two files mdCustomers and mdreports. This warning I get only when I try to run it in the IDE and is silent when I activated it with a button.

Romke


I'm afraid I have no idea what this may be! It has never happened before here and as far as I am aware there should be no reason for this.
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Thu Apr 12, 2012 6:44 am    Post subject: Reply with quote

Hello

I did have test a little more. For the reason I have no explanation. But I think loadComponentFromURL is seen an URL and for that reason not always trust.

When you store the macro's in MyMacro's then it can be you have less problems. From a little test it seems this is true. I do see this kind of problems also for the first time.

Romke
_________________
OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum
Back to top
View user's profile Send private message
cazbym
Power User
Power User


Joined: 16 Mar 2009
Posts: 63

PostPosted: Thu Apr 12, 2012 7:24 am    Post subject: Reply with quote

Hello,

Well moved all my macros out of the writer documents into MyMacros and all working as should. No idea why security problem - assume that you replaced documents path with your own - so strange. Anyway problem solved.

Many many thanks!! Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API 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