Page 1 of 1
[Solved] Passing values within form with sub forms
Posted: Sun Dec 09, 2012 6:23 pm
by aftershock
Hope I can explain this right.
I have this form "frmJobDaily"
The structure
I am able to select a customer, then below, a job address. To the right shows and dates where an entry has been made for the selected job address.
The drop down date field above the dates shown, I use to select a date and it will populate the controls to the right which show the details per date selected, and if nothing is on record it will be empty in which I enter new data for the employee hours and material used as well as a description for the selected date.
All works great, I have been able to call a report and send an invoice using the data entered, then making queries based upon the tables affected.
Now, the table control showing existing dates for the job is just that, for show. I use that and then select a date from the date drop down to get the details.
What I want is to dbl click on the table control and pass that to the date drop down. With searching through I have found the solution to get the cell value (thanx to the wise ones on this forum) but have yet to get past that point.
Code: Select all
Sub DoubleClick (oEV as object) 'Called by double click on table control
' wait 300
if oEV.clickcount <> 2 then Exit Sub 'Aborts if not double click
GetSecondColumn(oEV) 'calls Subroutine to get other fields/columns
End sub
Sub GetSecondColumn (oEV as object) 'Called by last line Sub ContactName()
'oMainForm = thisComponent.Parent.FormDocuments
oMainForm = thisComponent.Parent.FormDocuments
'oMainForm = oMainForm.getByName("frmJobDaily").getByName("Jobs").getByName("Filter Form")
oForm = oEV.Source.Model.Parent
o2Col = oForm.Columns.GetByName("Date")
msgbox "Linked text is '" & o2Col.String & "'"
msgbox oForm.Name
if oMainForm.HasByName("frmJobDaily") then
oMainForm = OMainForm.getByName("frmJobDaily")
'oMainForm = OMainForm.getByName("Customers")
'oMainform = oMainForm.thisComponent.DrawPage.Forms.getByName("frmJobDaily")
msgbox oMainForm.Name
end if
End Sub
I am trying to work my way back into the form to get back to the "Filter Form" so as to pass the value to "Date Field 1"
The macro works as far as giving me the msg boxes (helps me see what I am getting), but I get errors when I uncomment
Code: Select all
'oMainForm = OMainForm.getByName("Customers")
'oMainform = oMainForm.thisComponent.DrawPage.Forms.getByName("frmJobDaily")
My head is hurting right now after trying variations of methods to see If I can get further.

Re: Passing values within form with sub forms
Posted: Sun Dec 09, 2012 8:55 pm
by RPG
Hello
If you want work with a OOo-base I think it is good to start reading threads on the
tutorial forums.
When you want continue with macros I think it is good idea to get a better idea about the objects and the supported services and interfaces.
http://forum.openoffice.org/en/forum/vi ... 52#p224552
It is important to understand how the databasedocument is built.
The databasedocument can contain:
a) Formdocuments
b) ReportDocuments
c) Queries
d) Tables
A formdocument can contain more then one mainform. Each main form can contain more then one subform or more then one gridcontrol. Each gridcontrol or form, mainform or subform, can contain more then one control.
Romke
Re: Passing values within form with sub forms
Posted: Mon Dec 10, 2012 12:36 am
by aftershock
RPG I understand your wanting to direct me to documentations to read. I do this and will continue as it is presented.
Unfortunately in my case, documentation can get confusing and does not always help. I learn quicker by getting my hands dirty so to speak and I experiment.
When I post an issue I will try an be as detailed as possible so that one with the experience that I do not have may be able to point out my mistake and I hope as well the correct solution, in this case syntax, so I can see what I did wrong.
Re: Passing values within form with sub forms
Posted: Mon Dec 10, 2012 12:58 am
by RPG
Hello
I think you have to add
open to a line of the code.
I think this line
Code: Select all
oMainForm = OMainForm.getByName("frmJobDaily").open
I have no idea futher of your code.
Romke
Re: Passing values within form with sub forms
Posted: Mon Dec 10, 2012 1:03 am
by RPG
Hello
One important thing you have also to learn. The place where you get an error is real often not the place where you have wrong code. The place of the wrong code can be much earlier.
Romke
Re: Passing values within form with sub forms
Posted: Mon Dec 10, 2012 11:21 am
by Arineckaig
What I want is to dbl click on the table control and pass that to the date drop down. With searching through I have found the solution to get the cell value (thanx to the wise ones on this forum) but have yet to get past that point.
It is seldom easy to offer suggestions for debugging code unless a sample of the actual database file is attached to the post: complexities inherent in the OpenOffice API mean there is ample scope for error.
I learn quicker by getting my hands dirty so to speak and I experiment.
........................ in this case syntax, so I can see what I did wrong.
To assist such experiments with macros and the OpenOffice API, I would strongly recommend your consideration of the remarkable MRI extension created by Hanya. It is well suited for disclosing the properties, methods, interfaces and services applicable to any data form or form control contained within a Base form document. It has many features and can even supply suitable code for copying and pasting. You may find this crude
utility, also, helpful when using MRI to develop coding for a Base form document.
Re: Passing values within form with sub forms
Posted: Mon Dec 10, 2012 1:55 pm
by aftershock
Arineckaig wrote:
To assist such experiments with macros and the OpenOffice API, I would strongly recommend your consideration of the remarkable MRI extension created by Hanya. It is well suited for disclosing the properties, methods, interfaces and services applicable to any data form or form control contained within a Base form document. It has many features and can even supply suitable code for copying and pasting. You may find this crude
utility, also, helpful when using MRI to develop coding for a Base form document.
I just started using the Xray tool and having to figure it out. I will look at MRI.
Re: Passing values within form with sub forms
Posted: Mon Dec 10, 2012 9:01 pm
by Arineckaig
Xray and MRI each have their role.
Re: Passing values within form with sub forms
Posted: Mon Dec 10, 2012 10:55 pm
by RPG
Hello
I think the next code is maybe doing the same as your and does as how I undesrstand your question.
Code: Select all
Sub DoubleClick (oEV as object) 'Called by double click on table control'
' Maybe use when control key pressed
dim oControlDate' Sourcedate in a gridcontrol
dim oForm ' The form one level higher then the form of the date control
oControlDate=oEV.Source.Model
oForm=oControlDate.parent.parent.parent ' From control to gridcontrol to the formcontainer to form parentcontainer
dim o2Col' Destination control in a form
o2Col=oForm.getbyname("Filter Form").getbyname("Date Field 1")
o2Col.boundfield.setdate=oControlDate.boundfield.getdate 'move the date from one control field to an other
End Sub
If it is not working then it makes clear how you work with drilling up and down in the form what is already open. I have not test it and it is more an idea then working code.
Romke
Re: Passing values within form with sub forms
Posted: Mon Dec 10, 2012 11:56 pm
by aftershock
Arineckaig wrote:Xray and MRI each have their role.
I have tried Xray but MRI with the other link that has a form navigator showing the direction in which I must take to get my macro going seems to be the best help I have found so far when it comes to macros.
Thank you for that heads up.

Re: Passing values within form with sub forms
Posted: Tue Dec 11, 2012 12:06 am
by aftershock
RPG wrote:Hello
I think the next code is maybe doing the same as your and does as how I undesrstand your question.
Code: Select all
Sub DoubleClick (oEV as object) 'Called by double click on table control'
' Maybe use when control key pressed
dim oControlDate' Sourcedate in a gridcontrol
dim oForm ' The form one level higher then the form of the date control
oControlDate=oEV.Source.Model
oForm=oControlDate.parent.parent.parent ' From control to gridcontrol to the formcontainer to form parentcontainer
dim o2Col' Destination control in a form
o2Col=oForm.getbyname("Filter Form").getbyname("Date Field 1")
o2Col.boundfield.setdate=oControlDate.boundfield.getdate 'move the date from one control field to an other
End Sub
If it is not working then it makes clear how you work with drilling up and down in the form what is already open. I have not test it and it is more an idea then working code.
Romke
Since using MRI, I was quickly able to come up with:
Code: Select all
Sub DoubleClick (oEV as object) 'Called by double click on table control
' wait 300
if oEV.clickcount <> 2 then Exit Sub 'Aborts if not double click
GetSecondColumn(oEV) 'calls Subroutine to get other fields/columns
End sub
Sub GetSecondColumn (oEV as object, Optional oInitialTarget As Object)
'BasicLibraries.loadLibrary("XrayTool")
Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
Dim oParent As Variant
Dim oObj1 As Variant
Dim oObj2 As Variant
Dim sText As Date
oForm = oEV.Source.Model.Parent
oParent = oForm.getParent()
oObj1 = oParent.getByName("Filter Form")
oObj2 = oObj1.getByName("Date Field 1")
o2Col = oForm.Columns.GetByName("Date")
sText = o2Col.String
oObj2.Text = sText
End Sub
I dont know if I need
Globalscope.BasicLibraries.LoadLibrary( "MRILib" ) in the second sub or not, and I could probably do this all in 1 sub. I will study what you have posted.
Thanx to you and all involved. I think I have one more issue to solve to complete this but need to run some msgbox in the macro to find out how far it gets.
Re: Passing values within form with sub forms
Posted: Tue Dec 11, 2012 12:36 am
by aftershock
aftershock wrote:
Since using MRI, I was quickly able to come up with:
Code: Select all
Sub DoubleClick (oEV as object) 'Called by double click on table control
' wait 300
if oEV.clickcount <> 2 then Exit Sub 'Aborts if not double click
GetSecondColumn(oEV) 'calls Subroutine to get other fields/columns
End sub
Sub GetSecondColumn (oEV as object, Optional oInitialTarget As Object)
'BasicLibraries.loadLibrary("XrayTool")
Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
Dim oParent As Variant
Dim oObj1 As Variant
Dim oObj2 As Variant
Dim sText As Date
oForm = oEV.Source.Model.Parent
oParent = oForm.getParent()
oObj1 = oParent.getByName("Filter Form")
oObj2 = oObj1.getByName("Date Field 1")
o2Col = oForm.Columns.GetByName("Date")
sText = o2Col.String
oObj2.Text = sText
End Sub
I dont know if I need
Globalscope.BasicLibraries.LoadLibrary( "MRILib" ) in the second sub or not, and I could probably do this all in 1 sub. I will study what you have posted.
Thanx to you and all involved. I think I have one more issue to solve to complete this but need to run some msgbox in the macro to find out how far it gets.
Ok. "Date Field 1" is a Date control set to show dates as MM/DD/YY format.
sText pulls the date in MM/DD/YYYY format so it passes this string to "Date Field 1" but the Text modified event does not seem to fire. Do I need to force this in the macro? Reload or refresh is not a method or property recognized for this control.
Code: Select all
Sub SetDateAndRefresh (oEvent as Object)
msgbox "Here to Reset Date"
oForm = oEvent.Source.Model.Parent
msgbox "Setting Date"
oEvent.Source.Model.commit() 'save the Date selection to the host data-Form
'save all changes to the MainForm's Table
IF oForm.isnew THEN oForm.insertRow() ELSE oForm.updateRow()
'refresh the sub forms
msgbox "Going to refresh forms"
oForm.GetByName("Job Material").reload
oForm.GetByName("Job Time").reload
oForm.GetByName("Job Description").reload
End Sub
Re: Passing values within form with sub forms
Posted: Tue Dec 11, 2012 12:38 am
by aftershock
Code: Select all
o2Col.boundfield.setdate=oControlDate.boundfield.getdate 'move the date from one control field to an other
Property or Method not found.

Re: Passing values within form with sub forms
Posted: Tue Dec 11, 2012 9:57 am
by RPG
Hello
As programmer you have to learn how to solve such kind of problems.
In the error message you see on which part of the line you have the problem.
Romke
Re: Passing values within form with sub forms
Posted: Tue Dec 11, 2012 2:00 pm
by Arineckaig
aftershock asked:I dont know if I need Globalscope.BasicLibraries.LoadLibrary( "MRILib" ) in the second sub or not, and I could probably do this all in 1 sub.
Once you have loaded the "MRILib" library there is no need to load it again during an OpenOffice current session. There is even a case for creating a sub routine that checks whether the library is not already loaded before doing so again.
Re: Passing values within form with sub forms
Posted: Tue Dec 11, 2012 3:08 pm
by aftershock
RPG wrote:Hello
As programmer you have to learn how to solve such kind of problems.
In the error message you see on which part of the line you have the problem.
Romke
How can I dissecta a line with multiple objects to find which part is giving the error.
I will need to break it into multiple lines.
Im looking into it it.
Re: Passing values within form with sub forms
Posted: Tue Dec 11, 2012 3:15 pm
by aftershock
RPG wrote:Hello
As programmer you have to learn how to solve such kind of problems.
In the error message you see on which part of the line you have the problem.
Romke
Code: Select all
Sub Snippet(oEV as object)
'Called by double click on table control'
' Maybe use when control key pressed
dim sText
dim oControlDate AS Variant' Sourcedate in a gridcontrol
dim oForm ' The form one level higher then the form of the date control
oControlDate=oEV.Source.Model
'Xray oControlDate
oForm=oControlDate.parent.parent.parent ' From control to gridcontrol to the formcontainer to form parentcontainer
oControlDate = oControlDate.getbyname("DateField1")
dim o2Col AS Variant' Destination control in a form
o2Col=oForm.getbyname("Jobs").getbyname("Filter Form").getbyname("Date Field 1")
msgbox o2Col.Name
msgbox oControlDate.Name
sText = oControlDate.boundfield.getdate
' Xray sText
'exit sub
o2Col.boundfield.setdate="12/05/12" 'move the date from one control field to an other
End Sub
Ok, I broke it down into 2 lines. I get "Object variable not set on the last line" >> o2Col.boundfield.setdate="12/05/12"
Re: Passing values within form with sub forms
Posted: Tue Dec 11, 2012 5:00 pm
by RPG
Hello
The code I did wrote as example was the code I should use when I want do the same things as you do and as I understand your picture and your explanation good. You can see it is real different code. Maybe the best code maybe not. It is possible that other people do it in an other way. But I realy believe it is better then your starting code. But your own code, composed with the MRI, can be good code.
It is to you now to follow maybe the same idea and test it on each line for the values. You have also to understand if it is doing the same thing as you want. This means you must not start on a line with an error message but start checking each line and maybe each part. You have maybe also to change some methods or properties. I can not know what is the best method in your case for that reason I did go to the database field where I assume date types. If this is not true then try to discover what is the best for I cannot know. I only knew that a string type with a date vaue is not the same as date type for an uno-value. And to make it more complicated a BASIC date is different for a string and for a uno-date
I can even not know if your control does contain a database field. It is possible your control is not based on a database-field.
For the error message on the status line of the IDE editor there is message for which character give maybe the problem. Test for each part of the line what is not set. I have no idea.
aftershock wrote:o2Col.boundfield.setdate="12/05/12" 'move the date from one control field to an other
I think this is not possible. You can not set a date structure with a string value. Learn first what is your source of type. Learn to use the BASIC function Typename.
Code: Select all
o2Col.boundfield.updatestring("2012-05-12") ' Maybe this is possible. It can be your month and date is changed.
Be aware I did not test the code.
Edit: In a test I have learned I must use this code for updating a field.
oDateBox.boundfield.updatestring("2012-12-02") |
http://forum.openoffice.org/en/forum/vi ... ng#p255068
Read the thread above for a discussion about dates.
http://www.oooforum.org/forum/viewtopic ... t=sub+date
Edit: I have found back this old thread. I did also search for an other old post. There I did learned from Villeroy you can not use the number values. The number values for SQL are different then the number values for BASIC. |
Romke
Re: Passing values within form with sub forms
Posted: Wed Dec 12, 2012 1:06 am
by aftershock
I still have alot to learn and RPG reminds me of the guy in the Karate Kid who trained Daniel. RPG is forcing me to find the answers. This is good and this is what I would like to do. Makes me better at finding faults in code.
Whith that said, my question, Once I pass a value to a Date drop down box, how can I get it to trigger to "Text modified" event?
I have successfully been able to pass the date to the control using a macro, but I also want to fire the event in the same macro.
Re: Passing values within form with sub forms
Posted: Wed Dec 12, 2012 1:51 am
by RPG
Hello
aftershock wrote: Once I pass a value to a Date drop down box, how can I get it to trigger to "Text modified" event?
I have successfully been able to pass the date to the control using a macro, but I also want to fire the event in the same macro.
I don't know if I understand what you want. It is not possible in the way I understand it as far I know.
Possible is maybe
store a value in the control
commit the value to the field
then take the event of the field modified.of the same control.
An other way is maybe to make a listener. But I have little experience with listeners.
Romke
Re: Passing values within form with sub forms
Posted: Fri Dec 14, 2012 3:17 pm
by aftershock
RPG wrote:Hello
aftershock wrote: Once I pass a value to a Date drop down box, how can I get it to trigger to "Text modified" event?
I have successfully been able to pass the date to the control using a macro, but I also want to fire the event in the same macro.
I don't know if I understand what you want. It is not possible in the way I understand it as far I know.
Possible is maybe
store a value in the control
commit the value to the field
then take the event of the field modified.of the same control.
An other way is maybe to make a listener. But I have little experience with listeners.
Romke
After

and experiments I have found the solution, I think
Code: Select all
Sub DoubleClick (oEV as object) 'Called by double click on table control
' wait 300
if oEV.clickcount <> 2 then Exit Sub 'Aborts if not double click
GetSecondColumn(oEV) 'calls Subroutine to get other fields/columns
End sub
Sub GetSecondColumn (oEV as object, Optional oInitialTarget As Object) 'Called by last line Sub ContactName()
Dim oParent As Variant
Dim oObj1 As Variant
Dim oObj2 As Variant
Dim sText As Date
oForm = oEV.Source.Model.Parent
oParent = oForm.getParent()
oObj1 = oParent.getByName("Filter Form")
oObj2 = oObj1.getByName("Date Field 1")
o2Col = oForm.Columns.GetByName("Date")
oObj2.boundfield.updatestring(o2Col.String)
oObj1.GetByName("Job Material").reload
oObj1.GetByName("Job Time").reload
oObj1.GetByName("Job Description").reload
End Sub
So far it is working. Must go to work and will solve this in the evening if I dont encounter any bugs.
Re: Passing values within form with sub forms
Posted: Fri Dec 14, 2012 4:18 pm
by RPG
Hello
It is nice for you, you have succeed. You have learned now it is real difficult to write your own macros. For that reason I try to write macros who can be used without modifying. When I have found them I place once an example. Those examples can be used by people. It can then also learn how to work with OOo-base.
I do point real often to several other people like Arineckaig, DACM, Sliderule or Villeroy. The reason is they have a good understanding of how to use OOo-base without macros. I think they all use OOo-base in a way I don't use it. I think they use OOo-base for real business. I'm a home user with only a small database and was thinking, it was wrong, that macros was a good method for working with OOo-base.
Romke
Re: Passing values within form with sub forms
Posted: Sat Dec 15, 2012 1:27 pm
by aftershock
Ok, after further testing and finding a bug this should be the final macro. I was able to do this all in one sub.
Code: Select all
Sub GetExistingDates (oEV as object) 'When user clicks on an existing date shown for a Job in frmJobDaily
Dim oParent As Variant
Dim oObj1 As Variant
Dim oObj2 As Variant
Dim sText As Date
Dim oRowSet As Variant
Dim nRowCount As Long
Dim oTable as Variant
oForm = oEV.Source.Model.Parent
oTable = oForm.getByName("ExDates") 'Table on form showing existing dates
oRowSet = oTable.getRowSet() 'Gets the row count
nRowCount = oRowSet.RowCount 'of the table
oParent = oForm.getParent()
oObj1 = oParent.getByName("Filter Form")
oObj2 = oObj1.getByName("Date Field 1")
o2Col = oForm.Columns.GetByName("Date")
if nRowCount = 0 then exit sub 'if there are no rows in the table we must exit or we get an error
oObj2.boundfield.updatestring(o2Col.String)
oObj1.GetByName("Job Material").reload
oObj1.GetByName("Job Time").reload
oObj1.GetByName("Job Description").reload
End Sub
This may have been written to be shorter with less variables but I am still learning properties and methods. The MRI tool has helped quite a bit to show how to achieve this. Thanx for all who helped point me in the right direction.

Re: [Solved] Passing values within form with sub forms
Posted: Sat Dec 15, 2012 3:46 pm
by RPG
Hello
aftershock wrote:This may have been written to be shorter with less variables but I am still learning properties and methods
I think the method you did wrote your is good. Also using a lot of variables is good. When you have good names for your variables it does help you to understand your own code when you want re-use it later.
Romke