AUTHOR'S MAIN SITE   > > > > >  TABLE OF CONTENTS for Open Office database tutorials.

Open Office database, ooBase:
How to Make a Field with Auto Increment


You may find that the database being shipped with OpenOffice (ver.2 and higher) delights you as much as it has me. This page tries to help you use it.

Forget anything you may have heard about Adabas, which came with Star Office, the commercial version of Open Office 1. The current Open Office's database, "Base", aka "ooBase", is unrelated. And remember that Open Office, including ooBase, is free! But don't let that fool you. And it's not new. Big organizations, government and civilian, are adopting it as their standard office suite... and saving million$, but still Getting The Job Done.

There's more about ooBase in the main index to this material.

This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a narrow window. With most browsers, pressing plus, minus or zero while the control key (ctrl) is held down will change the texts size. (Enlarge, reduce, restore to default, respectively.) (This is more fully explained, and there's another tip, at my Power Browsing page.)

Page contents © TK Boyd, Sheepdog Software ®, 10/08.



Automatically Incremented Fields_______________

With ooBase it is easy to set up a field which automatically increments. This is often done for a primary key's field. Every time a new record is started, the field's value is filled in with the number one larger than the number in the previously created record; the user doesn't have to do anything. ooBase calls this "AutoValue". As far as I know, in ooBase only an integer type field can be made to do this. It is turned on or off with the "AutoValue" property for the field. If you wish to, you can even re-set the number which will be used for the next record.

I abhor conflating verbs and adjectives slightly more than I abhor ungainly neologisms, so I will be using "auto-increment" and "auto-incremented", to avoid convoluted expressions. I will also write them both with and without the hyphen, to help search engines find this page with either "spelling".

The Number in the Auto-incremented Field_______

Usually the number will "mean" not much, just as the serial number on bank notes means not much. In both cases, they merely serve to tell one instance of the item in question from another.

If, having created an autoincrementing field, you want to change the number which will be used next, you need the information in my short "How To" on changing auto-increment start numbers.

Creating an Auto-Increment Field_______________

It is easiest to create an auto-incrementing field (AIF) if you do it when you first create the table. How to add one to an existing table will have to be an "exercise for the reader" for now. If you have an existing table, and want to "add" an AIF, then create a new table with the same fields, plus your AIF, and import the data from the old table into the new one.

Using "Create Table":

If you use "Create Table" to create tables, creating autoincrementing fields couldn't be easier: Just set the field's type to Integer and the AutoValue property to True. As usual, if the field is to be the primary key, then you would also right-click on the little box at the left end of the row and select "Primary Key". You should see a small "key" icon in the field once you've done this. Making the field a primary key isn't required if you make the field autoincrement. But if you have an autoincrementing field in your table, give serious consideration to using that field as the table's primary key.)

Using the Tables Wizard:

The easy answer, if you use the Tables Wizard: If your autoincrementing field is to be your primary key, you can, (under ooBase 3.0.0, and probably others... but the exact text/ step numbers may vary)...

That approach will create a field called "ID" as the first field of the table, type Integer, AutoValue "true".

If you don't like the name, you can change it by editing the table after the Wizard has finished creating it. But do so early on, before you have a bunch of tables referring to the field by the name you want to change.

I prefer to use "Create Table". If you are content to do that, or use the Wizard as explained above, you can skip the next three paragraphs! They just go into some "what if"s.

You can also follow the same steps with one variation: Specify, say, six fields if you need six fields including the AIF. The name and type of the AIF can be changed in step 2. It is probably best to make the AIF the first in the table. The type will have to be "Integer", so you may need to change the type of the field you put there as a place-holder during step 1. Don't, during step 2, set the field's AutoValue property "true". During Step 3, use the "Use an existing field..." option, and do, here, tick the AutoValue box.

If you tick the AutoValue box in step 2, you will be asked for an "Auto-increment statement". Why bother to remember what you need to enter when you can have it done for you if you wait until step 3? (If you enter a "bad" auto-increment statement in step two, but do the right things in step 3, your mistake may cause ooBase, when you click on the Wizard's "finish", to report a problem with the CREATE TABLE operation. Just go back to step 2, say "no" to AutoValue for the relevant field and blank the "Auto-increment statement" box... even though you want AutoValue operating for it, do the right things in step 3. They will possibly override what you said in Step 2, and if they don't, you can open the table for edit once created, and turn auto-increment on for the relevant field by making its AutoValue property "true".)

Lastly, for the awkward kid in the back row, what if you want to set up the auto-increment field in step two? There is an expression you can put in the auto-increment statement field. I can't find it at the moment, but I know it can be done. It is probably the way to go, if for some reason I cannot fathom you wanted to do what seems like a Bad Idea to me, and make the value jump by ten for each new record.





Editorial Philosophy

This material is "browser-friendly"... in particular, you can (and I recommend that you do!) make your browser window narrow, so that you don't have to try to read long lines.

I dislike 'fancy' websites with more concern for a flashy appearance than for good content. For a pretty picture, I can go to an art gallery. Of course, an attractive site WITH content deserves praise... as long as that pretty face doesn't cost download time. In any case....

I am trying to present this material in a format which makes it easy for you to USE it. See the main index to this material for more information about the way it is posted.




Search the ooBase tutorials. Results will open in new page.

Custom Search


Ad from page's editor: Yes.. I do enjoy compiling these things for you... I hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!

PLEASE >>> Click here to visit editor's Sheepdog Software (tm) freeware, shareware pages <<< PLEASE


If you liked this ooBase tutorial, see the main index for information other help from the same author.

Editor's email address. Suggestions welcomed!     - - -    Want a site hosted, or email? I like 1&1's services.




Valid HTML 4.01 Transitional Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org


One last bit of advice: Be sure you know all you need to about spyware.

. . . . . P a g e . . . E n d s . . . . .