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

Updating or requery of Subform list box

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Fundi
OOo Advocate
OOo Advocate


Joined: 21 Sep 2004
Posts: 278

PostPosted: Wed Mar 12, 2008 2:45 pm    Post subject: Updating or requery of Subform list box Reply with quote

Hi
How do I requery or update a listbox in a subform so that it reflects a new addition in the underlying table?

I got a second from which the user can open if a particular value is not in the list of the list box. After completing the new entry the change is not reflected in the subforms list box. How can I
a) make the addition visible in the list box and
b) select the new entry right a way?

I have searched the forum but found nothing conclusive.

Thanks in advance
Fundi

PS Is there a macro and API tutorial or basic doc where to start learning how to code properly.
Back to top
View user's profile Send private message
Voobase
OOo Advocate
OOo Advocate


Joined: 21 Nov 2007
Posts: 400
Location: Australia

PostPosted: Fri Mar 14, 2008 7:56 pm    Post subject: Reply with quote

Hi Fundi, Macros made no sense to me either until I downloaded the XRAY tool (do a search for it) and started looking at all the properties (and methods) that your listbox and forms have. By looking at examples on the forums, slowly things have started to make sense for me.

With XRAY, once you have downloaded it, open the writer document (which it is, having attached macros) and click on the install button in the document. Make sure you have not set your macro security too high or it won't install. If you then press ALT F11 from within your database form, the basic macro's appear and you should see XRAY amongst them. Each time you open your database make sure you enable XRAY and hit the little plus sign to expand its "tree" out. (or an error occurs when it is called)

XRAY is called from within a macro you are trying to get working. You basically put XRAY oEv.source.model or XRAY oEv.source.model.parent on a line in your macro and up will pop either the component properties or form properties (respectively). Don't forget (oEv as object) must be with the sub name and you call the macro from an event from your component (best to look at some example macros on forum).

Anyway, back to your question. I know it is possible to refresh the list of a listbox by using the following macro code. First thing to try is to see if this works by calling it from a "Mouse Button Pressed" event from a button dropped on your Subform:

Code:
Sub Macro_Refresh (oEv as object)

rem XRAY oEv.source.model.parent.GetByName("Your_Listbox_Name")
rem above is an XRAY example

      oEv.source.model.parent.GetByName("Your_Listbox_Name").Refresh

rem Name of your listbox is case sensitive

rem oEv.source.model is the button
rem oEv.source.model.parent is the Form which the button is on.
rem Then using GetByName to get the listbox (from the form) and refresh to refresh it

End sub


The best way to call it in your situation, I assume, is from a "When recieving focus" event of your ListBox. Have the above code pasted in your basic macros (Alt F11) and edit the properties of your listbox so the event mentioned above points to this code.

If you are calling it from your listbox event, the refresh line in code could be reduced to (although the previous code will still work):

Code:
oEv.source.model.Refresh


This is because from a push button, the path an event has to go to get the listbox component properties is by going to the form first (parent), then it can obtain the listbox compent by using "getbyname". If the listbox itself calls it then it already knows where its properties are.

Hope this makes sense. I think it should answer your first question (if not let me know), however the question about "select the entry right away" might be more difficult. It should be possible with macro somehow. If I think of it I'll let you know. Otherwise someone else might have answer.

Cheers

Voo
Back to top
View user's profile Send private message
Fundi
OOo Advocate
OOo Advocate


Joined: 21 Sep 2004
Posts: 278

PostPosted: Sun Mar 30, 2008 10:29 am    Post subject: Reply with quote

Hi Voobase

A belated but big thank you for your reply to my message. It is spot on. Sorry for the delay but work did not allow me to continue but now I can.

I will check out this XRAY a bit later. Thanks for the Tip.

I tried to use your code but something is not quite right.
On executing the code I get a flag on this Line:
Code:
oEv.source.model.parent.GetByName("ListBoxCategory").Refresh

with the error message:
Basic runtime error
An exception has occurred
Type: com.sun.star.container.NoSuchElementExceptionMessage: .

It seems not to find the control. I pasted the name so no way that the case sensitivity can interfere.

What I think it is is that the control sits on a subformgrid. The button that executes it sits on the main form.
But I tried to link the macro to the "onGotFocus" event of the subform. but I'm getting the same error message.

By the way is there anywhere a reference to the Macro language?

Thanks for any help.
Back to top
View user's profile Send private message
Voobase
OOo Advocate
OOo Advocate


Joined: 21 Nov 2007
Posts: 400
Location: Australia

PostPosted: Wed Apr 16, 2008 2:52 am    Post subject: Reply with quote

Hi Fundi. Sorry for the late reply but have been out of town with work, overworked and underpaid etc. How did you go with your listbox?

If your list box control is part of a subform grid and the button is part of your mainform, the refresh line may need to look more like this:
Code:
oEv.source.model.parent.GetByName("SubFormName").GetByName("TableGridName").GetByName("ListBoxCategory").Refresh


I think that should work even though the listbox control is part of a table control grid on your subform. If you have got XRay to work you could try calling it by XRay in stages, i.e try
Code:
XRay oEv.source.model.parent.GetByName("SubFormName")
first, then add the next bit etc untill you see the properties of your listbox control.

Just for reference, a quick explanation of the structure most forms and controls follow (assuming you have (oEv as object) next to the name of your macro).....

If you are calling on mainform properties from an event from your mainform the properties are found at:
Code:
oEv.source


If you are calling on a controls properties from an event from that control the properties are found at:
Code:
oEv.source.model


If you are calling on mainform properties from an event from a control on that mainform it would be:
Code:
oEv.source.model.parent


If you are calling on a control's properties from a mainform event that the control is sitting on, then:
Code:
oEv.source.GetByName("ControlName")


This can be extended to calling subforms and table grids and controls on them as I outlined at the start of this reply.

cheers

Voo.

ps.Useful stuff...
Basic Programmers Guide
http://wiki.services.openoffice.org/wiki/Documentation

Andrew Pitonyak macro examples
http://www.pitonyak.org/oo.php

Forms and dialogs pdf and Database Development pdf by C.Benitez
http://www.geocities.com/rbenitez22/

But in reality, the best way to learn macro programming is tto search the forums for examples as you progress through your project. Reading something like the "Basic Programmers Guide" before you have an understanding of macros would only make your head explode! Very Happy I think some things are best left for reference.
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