[Solved] Subform synchronization

Discuss the database features
Post Reply
george++
Posts: 15
Joined: Mon Jul 11, 2011 9:42 pm

[Solved] Subform synchronization

Post by george++ »

Hi,
I have a main form and a subform. I need to syncronize the subform when I make a change in a record of the main form.
Unfortunatelly I dont know much about macros and events. Is there anyone can help me?

Thanks in advance
Last edited by george++ on Sat Nov 10, 2012 11:08 pm, edited 1 time in total.
OpenOffice 3.3 on WindowsXP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Subform synchronization

Post by Villeroy »

method #1: Go to another record and then back to the modified record.
#2: Add a push button to the subform with property "Action"="Refresh form".
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
george++
Posts: 15
Joined: Mon Jul 11, 2011 9:42 pm

Re: Subform synchronization

Post by george++ »

Villeroy, thank you very much. The second method works like a charm!
Just for fine tuning:Is it possible to generate a "Refresh" action of the subform when a list box, from the main form, changes it's selection?
OpenOffice 3.3 on WindowsXP
User avatar
DACM
Volunteer
Posts: 1138
Joined: Tue Nov 03, 2009 7:24 am

Re: Subform synchronization

Post by DACM »

george++ wrote:Is it possible to generate a "Refresh" action of the subform when a list box, from the main form, changes it's selection?
The same 'Refresh form' action applied to a push-button on the SubForm will also process List Box selections on the MainForm. If you prefer a more automated approach, then you'll need a macro applied to an appropriate List Box Event. Here's a demo of both techniques:
http://forum.openoffice.org/en/forum/vi ... 13#p252113
...
AOO 4.1.x; LO 4.2.x; Windows 7/8 64-bit
Warning: Avoid embedded databases --> Solution: Adopt a portable 'split database' folder
Soli Deo gloria
george++
Posts: 15
Joined: Mon Jul 11, 2011 9:42 pm

Re: [Solved] Subform synchronization

Post by george++ »

Thank you again.
I looked into the code and although I am an experienced C++ programmer I feel helpless because I can't find where are the properties of an 'object' and what are represent.
Let's say:

Code: Select all

oForm = oEvent.Source.Model.Parent
I don't know, for example, that the object has a property named 'Source' (or method) and the 'Source' has a 'Model' and the 'Model' has a property named 'Parent' (or method)
For example, what represents the 'Model'?
I search to the Wiki section but I didn't find detailed explanations and answers to the questions above.
I don't know where to start.
OpenOffice 3.3 on WindowsXP
User avatar
DACM
Volunteer
Posts: 1138
Joined: Tue Nov 03, 2009 7:24 am

Re: [Solved] Subform synchronization

Post by DACM »

I see that you've marked this thread 'Solved' so I presume you're happy with Villeroy's solution. That's excellent. :D

With reguard to your follow-up question about List Boxes, I presume from your response above that you're simply expressing an interest in the *ooBasic macro language or underlying UNO API -- in general -- because you're an experienced C++ programmer. I'll offer you some links (below) as food-for-thought on the topic, but I don't recommend learning anything about macros or objects in pursuit of an automated solution to your List Box question.

Concerning your List Box question: I assumed that you had tested the push-button solution with a List Box, so I offered the additional macro-driven solution in response. The macro was offered as a plug-in solution requiring no additional knowledge beyond built-in Base facilities. In other words, the manual push-button solution requires you to dive under-the-hood to assign an appropriate form-refresh 'action' while also placing the button on the appropriate SubForm using the Form Navigator. Likewise, a boilerplate macro requires you to copy&paste the macro to your Base (.odb) document, assign the macro to the designated 'event' on the Events tab of the List Box, and ensure the macro code reflects the correct SubForm 'name' as reflected in the Form Navigator. That's it. There's no intent to drive you into actual coding in a case like this. For example...

Given the following macro from the demo file:
  • Code: Select all

    Sub RefreshForm (oEvent as Object) 'Form > List Box > Events > Execute action
    	oForm = oEvent.Source.Model.Parent
    	oEvent.Source.Model.commit() 'save the List Box selection to the host data-Form
    	'save all changes to the MainForm's Table... compiler bug doesn't allow comments on an IF-THEN-ELSE line
    	IF oForm.isnew THEN oForm.insertRow() ELSE oForm.updateRow() 
    	oForm.GetByName("SubForm1").reload 'reload the SubForm's individually to avoid jumping to the first record
    	oForm.GetByName("SubForm2").reload 'reload the SubForm's individually to avoid jumping to the first record
    End Sub
Your task is to:
  • 1. copy this macro to your Base (.odb) file as shown in the demo (.odb) file
    2. assign the macro to the event indicated in the macro comment: Form > List Box > Events tab > Execute action
    3. replace the name of your SubForm as appropriate in the macro code; your SubForm name is determined by opening the Form Navigator
    4. delete the last line of the macro if you don't have multiple SubForms to refresh
So your macro will likely become:
  • Code: Select all

    Sub RefreshForm (oEvent as Object) 'Form > List Box > Events > Execute action
    	oForm = oEvent.Source.Model.Parent
    	oEvent.Source.Model.commit() 'save the List Box selection to the host data-Form
    	'save all changes to the MainForm's Table... compiler bug doesn't allow comments on an IF-THEN-ELSE line
    	IF oForm.isnew THEN oForm.insertRow() ELSE oForm.updateRow() 
    	oForm.GetByName("SubForm").reload 'reload the SubForm's individually to avoid jumping to the first record
    End Sub
The only change is the SubForm name ("SubForm") and elimination of the last line as necessary. Actually, "SubForm" is the default name assigned by the Base Form wizard, so you'll find the exact final code above in many of my demos. I simply failed to point you to one of those demos in this case, so slight modification became necessary. :oops: That would have eliminated steps 3 & 4 above -- leaving a relatively simple, 2-step process similar to that of implementing a push-button.


As promised, some food-for-thought on macros. Note that Introduction into object inspection with MRI]object inspectors are available as add-ons or extensions:
Last edited by DACM on Sun May 04, 2014 3:25 am, edited 1 time in total.
AOO 4.1.x; LO 4.2.x; Windows 7/8 64-bit
Warning: Avoid embedded databases --> Solution: Adopt a portable 'split database' folder
Soli Deo gloria
george++
Posts: 15
Joined: Mon Jul 11, 2011 9:42 pm

Re: [Solved] Subform synchronization

Post by george++ »

I'll offer you some links (below) as food-for-thought on the topic, but I don't recommend learning anything about macros or objects in pursuit of an automated solution to your List Box question.
Thanks a lot
OpenOffice 3.3 on WindowsXP
Post Reply