Alright those macros are pretty simple. But before you go any further you should under stand one thing
sub onClickButton_reportWizard( oEvent as object )
What does "oEvent as object" mean?
For all controls on a form, when you assign an event to a macro there is always one parameter passed to the macro - this parameter is a Structure and is named the EventObject - You can find the documenation for this at:
http://api.openoffice.org/docs/common/r ... bject.html
Now that documentaiton is fairly sparse, but it does show that there will always be at least one member of the structure and thast is named Source.
In our case then the oEvent.Source is the button that was clicked.
Sometimes the EventObject will have additional pieces of information also - additional memerbs - but it will always have this Source.
( An Important point here is that this is always TRUE for events from Controls on Forums but alwyas true for other types of events in OpenOffice.org )
Fine - next piece of information to understand - all controls on a form belong to a hierarchy ( ownership strucure ). You can see this in the form navigator window:
The hierarchy always begins with the root "forms", this is a container which owns all the controls on the form, visible or hidden.
Just below this root "forums" is the control named "MainForm". This first level is always a control of type "dataform" and is a non-visual control that acts as the glue between the records in your database and the visual controls on the form.
( NOTE: When you use the Form Wizard to create a form the top level form is always nemed MainForm and if you add a sub form it is named SubForm )
So - Every visual control ona form will belong to one of these "dataform" controls. This dataform control is referred to as the visual controls "Parent".
Open the Employee form in edit mode again and open the forum navigator. ( you can do this on the "Form Design" toolbar - it is the 5th button from the left )
Now select the control "MainForm", right click and select "Properties".
Select the tabl "Data"
Like I said this is the link to the actual data. In this case we are connected directly to the Table, Employees.
This is emportant because to run our report for just one Employee we must find out which employee is currently being viewed in the form.
With this abiltiy to get back to the actual link to the table this becomes easy.
For our purposes what we really want to know is:
What is the value of the EmployeeID field for the employee record currently in the form?
Here is the macro updated to find that information.
Code: Select all
sub onClickButton_reportWizard( oEvent as object )
dim tblEmployees
dim EmplID as integer
REM oEvent is an EventObject
REM Source is the control that called the event - the button
REM Model is what we use when we want to get to properties avialable at design time
REM Parent is the name of the contol that the button belongs to
tblEmployees = oEvent.Source.Model.Parent
EmplID = tblEmployees.getInt( tblEmployees.FindColumn( "EmployeeID" ) )
print "Currently Viewing record for employee with ID =" & EmplID
end sub
Go ahead and copy the above macro into your library, save it, close the form and run it...now click the first button.
Move to the second record and click the button again.
See even though the EmployeeID field is not displayed on the form, because we are connected to the Employees table then we can get any field we want.
The acutal documentaiton for the getInt function can be found at:
http://api.openoffice.org/docs/common/r ... tml#getInt
and the documentaiton for the findColumn function is at:
http://api.openoffice.org/docs/common/r ... findColumn
Now make the changes to the onClickbutton_reportBuilder to also get the EmployeeID value.