Openoffice.Org Base Macro Programming by Andrew Pitonyak
Total Page:16
File Type:pdf, Size:1020Kb
OpenOffice.org Base Macro Programming By Andrew Pitonyak Last Modified Tuesday, July 28, 2009 at 09:54:04 PM Document Revision: 43 Information Page Copyright This document is Copyright © 2005-2009 by its contributors as listed in the section titled Authors. You can distribute it and/or modify it under the terms of the Creative Commons Attribution License, version 2.0 or later (http://creativecommons.org/licenses/by/2.0/). All trademarks within this guide belong to their legitimate owners. Authors Andrew Pitonyak Feedback Maintainer: Andrew Pitonyak [[email protected]] Please direct any comments or suggestions about this document to: [email protected] Acknowledgments I find it difficult to properly credit all of my sources, because so many people are helpful in an en devour of this size. There are, however, a few people who do indeed stand out in my mind as having provided significant encouragement. I have no explanation as to precisely why my wife Michelle allows me to spend so much time working with OpenOffice.org. Perhaps she is really the person that you should thank for my productivity. I Love you Michelle, you complete me. All of the people with whom I have interacted at Sun Microsystems have been very tolerant and patient with my endless questions. In the creation of this document, Frank Schönheit, however stands out in this regard. Mr. Schönheit spends a lot of time helping people with problems and questions, and most notable for me, he answers my questions. Thank you Frank! There is a large community volunteering their time with OpenOffice.org. Drew Jensen has stood out in my mind as an incredibly prolific and knowledgeable individual. Drew clearly has vast experience using database products, and he has brought this vast experience to the OOo community. He has created numerous excellent examples on the OOo Forums and mailing lists. Thank you Drew. There is a large community of helpers, who are simply too numerous to mention. I owe you all a thank you for your help and encouragement. In the general community, however, I will single out G. Roderick Singleton, who helps numerous people every day on the mailing lists. He also very proactive in keeping the documentation up-to-date. Mr. Singleton, I thank you for all of your help as well. This document is updated a lot, so it hardly makes sense to track changes at this time. Perhaps when I come up with at least a version 1.0. Table 1. Modification History Date Comment 9/23/06 Integrated changes from Jo <[email protected]> 3/13/07 Moved document to a new format. 4/4/07 Discovered that I did NOT transfer the macros. 1/30/08 Comments related to fields in forms. 2/18/08 New changes coming for OOo 3.0; watch out! I encourage people to turn on change tracking in OOo (Edit > Changes > Record) and make corrections, enhancements, and/or updates to this document. When you are finished, please send the document to me for integration into the final document. Please make note of the “Last Modified” date (Tuesday, July 28, 2009 at 09:54:04 PM) and the revision number (43) so that I will know if you have the latest document version, which makes my life much easier. iii Table of Contents Information Page........................................................................................................................2 Copyright...............................................................................................................................2 Authors..................................................................................................................................2 Feedback...............................................................................................................................2 Acknowledgments.................................................................................................................2 Table of Contents.......................................................................................................................v 1. Introduction...........................................................................................................................1 1.1. Introductory comments.................................................................................................1 1.2. Document organization and introduction......................................................................1 1.3. Prepare for big changes in OOo 3.0..............................................................................2 2. Storing images (binary data) in Base....................................................................................4 2.1. Create the initial Base document...................................................................................4 2.1.1. Using the GUI........................................................................................................4 2.1.2. Using a macro........................................................................................................4 2.1.3. Using a macro to open the wizard.........................................................................5 2.2. Create the table..............................................................................................................5 2.2.1. Using the GUI........................................................................................................5 2.2.2. Using a macro........................................................................................................6 2.2.3. Using SQL statements to modify tables................................................................8 2.2.4. Refresh the tables..................................................................................................8 2.2.5. Creating and deleting tables using SQL................................................................9 2.2.6. Increase a field©s length.......................................................................................11 2.3. Create a form...............................................................................................................11 2.3.1. Using the GUI......................................................................................................11 2.3.2. Using a macro......................................................................................................13 2.4. Open a form using a macro.........................................................................................17 2.5. Accessing the binary data............................................................................................20 2.5.1. Adding binary data..............................................................................................20 2.5.2. Extracting binary data..........................................................................................22 3. One-To-Many relationships................................................................................................25 3.1. Create the tables..........................................................................................................25 3.1.1. Create the DEALER table...................................................................................25 3.1.2. Create the ITEM table.........................................................................................26 3.2. Define the data relationships.......................................................................................28 3.3. Add data to the DEALER and ITEM tables................................................................29 4. Forms..................................................................................................................................32 4.1. The internal object model............................................................................................32 4.1.1. A control©s shape is in the draw page..................................................................32 4.1.2. A draw page contains forms................................................................................33 4.1.3. A control©s data model is in a form......................................................................34 4.1.4. A control©s view model is in the controller..........................................................35 v 4.1.5. Enabling and setting controls visible ± an example............................................36 4.1.6. Finding a control from an event ± an example....................................................36 4.1.7. Control connected to a database..........................................................................37 4.1.8. Control model summary......................................................................................38 4.2. Database Forms act like a result set............................................................................38 4.2.1. Duplicate record macro.......................................................................................39 4.3. Show one item and the corresponding dealer.............................................................42 4.4. Use a combo box with the dealer id............................................................................44 4.5. Use a list box with the dealer name............................................................................45 4.6. Relations in a single table...........................................................................................47 4.6.1. Solution................................................................................................................47 4.6.2. Solution