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

Subforms not being created with main form

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
Zerohawk
General User
General User


Joined: 12 Nov 2005
Posts: 12

PostPosted: Wed Dec 21, 2005 10:37 am    Post subject: Subforms not being created with main form Reply with quote

I'm trying to work with a layaway DB that has the following tables:
LAYAWAY_HEAD
LAYAWAY_PAYMENTS
LAYAWAY_TOTALS

And I have a form set up to add entries into it. The layaway_head is the main table for the form, and the other two were added as subfomrs, linked to the head's ID.

When I add a new entry into the form, I have to first enter the head data, then navigate away from it and back to it, then enter the subform data, then navigate away and back to it. Then its finaly updated. It doesn't create the subform records at the same time it creates the main table records.
Back to top
View user's profile Send private message
DrewJensen
Super User
Super User


Joined: 06 Jul 2005
Posts: 2616
Location: Cumberland, MD

PostPosted: Wed Dec 21, 2005 12:11 pm    Post subject: Reply with quote

Hi zerohawk,

Glad it is working for you - well mostly, anyway..

It kind of works like this because each dataform has to write its record out as a single transaction. When the master table is pushed into insert mode, the subforms end up having to blank, since there is no foreign key available - until you actually post the update to the database. At this time they should reload themselves - but you are right, they do not seem to do this. Therefore the back and forth to a control on the master.

Anyway, assuming the form is similiar to the one from before

http://img55.imageshack.us/my.php?image=layawayform0nl.jpg

Then you can fix this with a very simple macro.

I don't remember if you needed a macro before, if not you can add one now.

Tools>macros>Organize Dialog
Create a new library - for example name it Layaways
The library has a default module "Module1" created.
Select Edit
A default sub procedure is created named MAIN. Fine leave it blank.

Here is a the four line macro that will fix this problem.

Code:
sub AfterRecordAction_TICKET( oev as object )

  oev.source.getByName( "ITEMS" ).reload
  oev.source.getByName( "PAYMENTS" ).reload

end sub


Save the library

Now back in base open the form in edit mode. Open the form navigator and highlight the main embedded dataform control. On my form it is named TICKET. Make sure the two subform controls are named the same as what is in the macro above - or rather make sure they match, including case, and if not change one side or the other.

anyway - right click on the master dataform TICKET and select properties.

On the EVENT tab go to the 'After Record Action' event and click on Assign. Click on the Layaway library, click on Module1 and select AfterRecordAction_TICKET. Hit the done buton, and save the form.

Now when you run the form and enter a new layaway ticket, when the record is posted to the database, the table links are reloaded AFTER a new auto generated key exists and the sub-form grids are ready to take inserts.

Drew
_________________
Blog - http://baseanswers.spaces.live.com/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Zerohawk
General User
General User


Joined: 12 Nov 2005
Posts: 12

PostPosted: Wed Dec 21, 2005 2:25 pm    Post subject: Reply with quote

Thanks for the info, fixed everything.

I'm wondering, will the same thing work to update my controls for the Balance Qs?
Back to top
View user's profile Send private message
DrewJensen
Super User
Super User


Joined: 06 Jul 2005
Posts: 2616
Location: Cumberland, MD

PostPosted: Wed Dec 21, 2005 3:35 pm    Post subject: Reply with quote

Funny you would mention that...I was thinking about just that subject. When I got looking at the database again, I recalled that as something I meant to address. Yes, basically the same process, just attached to different dataforms and reloading others also. If you like I will put those couple lines together, or you can have at it yourself.

I have a question for you. Looking at our thread on this and the database that resulted would you mind if I take it all, clean up the flow of how it got put together and moved the whole thing over as a second tutorial. A few poeple have asked about one that uses sub-forms, and this might be perfect - plenty of sub forms, views and a tiny bit of basic code. I will simply supply my copy of the database with all the bogus information, as in what Brad Pitt put on layaway... Very Happy
_________________
Blog - http://baseanswers.spaces.live.com/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Zerohawk
General User
General User


Joined: 12 Nov 2005
Posts: 12

PostPosted: Thu Dec 22, 2005 6:42 am    Post subject: Reply with quote

Wouldn't mind at all if you did, I think it would be great. There is alot of info we've covered that would be excellent if it was one of the tutorials. I didn't know anything before we got started doing this, and now I've actually put together half a dozen different DBs for work after learning all the ins and outs of it here.

Might be a good idea to put a bit of emphasis on creating more than one subform, took me a little while to wiggle that one in.

I'll come back and ask for help if I can't get the job done, but I think I know how to wiggle it.
Back to top
View user's profile Send private message
DrewJensen
Super User
Super User


Joined: 06 Jul 2005
Posts: 2616
Location: Cumberland, MD

PostPosted: Thu Dec 22, 2005 6:48 am    Post subject: Reply with quote

I'll....as the capitalist, exploitative and cult affirming slogan from Nike goes...just do it!

Have a joyous holiday season then...

Drew
_________________
Blog - http://baseanswers.spaces.live.com/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Zerohawk
General User
General User


Joined: 12 Nov 2005
Posts: 12

PostPosted: Fri Dec 23, 2005 8:38 am    Post subject: Reply with quote

Ok, things didn't go so well.

What I tried to do to get the totals to work was to write a similar function to the one you tossed me for each of the table subforms Items and Payments, and set them up to run on a Record Action, just like the main form did, and then told the forms containing the totals to refresh...

Didn't work, and I probably should have guessed that it wouldn't, because the subforms don't have the scope to reach the totals which are above it, do they?
Back to top
View user's profile Send private message
DrewJensen
Super User
Super User


Joined: 06 Jul 2005
Posts: 2616
Location: Cumberland, MD

PostPosted: Fri Dec 23, 2005 10:33 am    Post subject: Reply with quote

Without going and looking at the form, you can get to anything inside the event handler code.

You don't have to start with

Code:

oev.source


but rather with the first embedded dataform object using

Code:

thiscomponent.dawpages.getByIndex(0)


Then if you go to code snippets I have a couple of routines that you can copy and past into your library that will let you find any control by name. In fact there are other routines available also, not just mine.

http://www.oooforum.org/forum/viewtopic.phtml?t=23919&highlight=form

But the point is you reload the embedded dataform object that uses the view to generate the totals.

Drew
_________________
Blog - http://baseanswers.spaces.live.com/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ehanuise
General User
General User


Joined: 26 Oct 2004
Posts: 21

PostPosted: Tue Jun 27, 2006 10:17 pm    Post subject: Reply with quote

is there an (easy) way to add this as a ne line action to a textarea or button in the form ?
(I see that you can link actions to things such as getting or losing focus, it'd seem quite elegant).

The thing is it seems to require a macro to be defined, is there no way to add just a generic line of code that reloads the form the area/button belongs to, independently of its name ?
(still haven't found the docs to the apparently thousands of functions ther's available.)
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 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