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

Open Office Database Tutorials

Linking to images from a database using path specifiers

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 ®, 2/06-6/09.


Where we're going

You will learn how to make a small database with images. In the tutorial they are photos, but they could also be diagrams, drawing, etc. This isn't a very demanding tutorial. But it does show you the "tricks" of something that has many uses. It is a sequel to another tutorial I have put on the web for you which addresses the same question... but solves it a different way! It would be best to read that tutorial first, even if you only skim through it.

Specifically, we will create a database with pictures of some North American birds. (The photos are provided for you.) Each record will consist simply of an index number, the bird's name, and the name of the file holding the bird's photo.

The tutorial will show you how to get the image to display on your form, even though the image isn't actually inside the database. All the database holds is information on where to find the image. This tutorial also gives you some help with details of creating and editing form designs, but the other tutorial gave more help.

Before we delve into the tutorial, I would like again to thank the contributors to the ooBase forum at OOoForum. They showed me how to do images the "embedded" way, and the "by paths" way.

You can download a version of the first database from the link in its tutorial.

For the "by paths" version, you need several things, and you will have to set them up by hand... but instructions are given, and the images are available for download.


Heart of the story

Set up the table....

Create a new database. Put it in it's own folder, call the folder whatever you like, and the database "BirdsWImagesByPath". (Most of the names I've suggested could be different, if you felt strongly about it.) Name from "BirdsW(ith)Images". It doesn't need to be registered, but registering it is probably a good idea, as it "costs" so little.

Set up a table. (Create in Design View would probably be best, but the finished result doesn't carry any "signature" of which tool you used.)

Fields:

Index (Integer:INTEGER, Autovalue=yes,
                 primary key)
PathToBirdsPicture (Text:VARCHAR, length 30)
Name (Text:VARCHAR, length 30)

Be sure to set Index as primary key.

Yes... my name for the second field is a little long.

Save the table as BirdsWImagesBPT1. (The names don't have to be unique, but I like to fight ambiguity. The "BP" part is for By Paths.)

I'll give you sample data in a moment. Just create the table for now.


Now catch some rabbits... umm... some bird pictures

The techniques explained in this tutorial allow you to store photos of whatever you want. For the sake of the tutorial, I have made a collection of photos of some birds available. (You may make whatever use you wish of those photos, except a use that restricts anyone else from doing the same. I assert ownership of their copyright. Don't get too excited... they're not good photos!)(You can access a vast library of royalty-free images online at a sister project of Wikipedia, by the way.)

They are in a Windows "self-extracting archive" prepared with WinZip, for which the following instructions apply. They are also available as a mere .zip file, for which the following instructions partly apply.

Once you have downloaded the archive, put it in the folder you created earlier, BirdsWImagesByPath. Unzip the images into that folder. The archive is self extracting... you only need to double-click on it. The unzipper will start up, and ask you where (what folder) to store the images. It puts 10 small .bmp files in that folder. Each one is named for the bird shown in the file. Each is about 200k. (That's probably bigger than it needs to be.)

In the other tutorial, I told you that once the database was built, you would no longer need the .bmp files. And that was true. When the database was built as we built the other one, when we were done, the images were inside the database, an integral part of it.

Not So This Time.

This time, we only store in the database information about WHERE the .bmp image is! This approach has pros and cons, which are left as an exercise for the student.


And now for some data....

Set up a simple data entry form, using the Wizard....

Step 1: You only have one table, and no queries, so the only thing you need to know is that you select just PathToBirdsPicture and Name. The easy way to do this is to click the ">>" and then select the Index field and send it back to the "Available fields" list.

Step 2: There's no need for any subforms. Click Next, which will take us straight to step 5.

Step 5: Arrange the controls as a "Data Sheet". This will make the form look almost like the table it relates to. Click Next.

Step 6: Leave the tick in front of "The form is to display all data". Do not tick "The form is to be used for entering..." Do not click on any of the "Do not allow...." boxes. Click Next.

Step 7: Play with these settings if you wish... but it isn't necessary. Click Next.

Step 8: Name the form "BirdsWImagesBPF1" (You'll probably merely have to change the penultimate character), select "Work with the form", and click "Finish".

Enter the following data. You may want to adjust the widths of the columns first.

PATHTOBIRDSPICTURE  //  Name
Crow.bmp               Crow
Mallard.bmp            Mallard Duck
Chickadee.bmp          Chickadee

That's enough to test things with.


Form with image....

Now we'll make a form which displays the image of whatever bird you choose.

Use the Form Wizard to get things started....

Step 1: Put the PathToBirdsPicture and Name fields on the form.

Step 2: No sub-form. (You will skip steps 3 and 4)

Step 5: Data Sheet for layout.

Step 6: Defaults. ("Display all.." / allow all changes)

Step 7: Whatever.

Step 8: Call it With Image

... and don't expect it to be working... yet.

Close the form, then re-open it in the editing mode.

(Re-size the data sheet, making it something more sensible.)

From the "More Controls" palette add an "Image Control". Drag it out to roughly 4cm x 4cm.

Double click on it (still in edit, or "design" mode), and you should get the control's properties.

On the "data" tab, "connect" the control to the PathToBirdsPicture field.

On the "general" tab, be sure that "Scale" is set to "Keep Ratio". (This option was added in ooBase's version 3.1, and very welcome it is, too!)

Run the form. You should now see whatever graphic is specified when you click on any record in the data sheet.


Odds and ends....

== 1 ==

A minor tidy: You really don't need to see the text of the PathToBirdsPicture in the data sheet, do you? I included it on the first pass through this, just to keep you reassured.

You could have done everything as above, except in step 1 left out PathToBirdsPicture from the fields in the data sheet. The form would have worked because the form's MainForm (Confusing, that... two uses of "form". Beware.) is tied to the table, and thus all its fields are available).

If you want to edit our existing form, you can simply right click on the PathToBirdsPicture column of the data sheet and select "Delete column".

== 2 ==

In a moment, I'll show you how to create a slightly different display form. First a warning: If you "play" with the following before making the name field "read only", you can "damage" the data in the underlying table. If you start getting strange results, use your BirdsWImagesF1 form to look at what is in the table. If it has been corrupted, save and close the display form you are working on, repair the data, then resume editing the display form.

Launch the new form wizard again

Step 1: Just Name

Step 2: No subform

Step 5: "Columnar, Label on top"

Step 6: As before, defaults.

Step 8: "Display by bar"

Close the resulting form, re-open in design mode.

Add image control; connect it to PathToBirdsPicture.

Add navigation bar. (You'll find it at the bottom of the "more controls" palette.)

Use the form navigator to select JUST the txtName text box. (You can also get to it by right-clicking on it, and electing to ungroup it and its label.) (New to Form Navigator? I have an introduction to form navigator for you.)

Change its Read Only property to "yes".

That should give you something that works.

For the purposes of this display form, you probably would want to set to "hide" the navigation bar's "acting on record" properties, and maybe others.


Fancier paths...

In this tutorial, we have worked with images in the same folder as the database. Can you have the photos elsewhere? Yes.... I believe you can. For instance, if you had them on a CD, and you knew that any system the database was going to run on would refer to the CD drive as "D:", then I believe that you could, say, put "D:\crow.bmp" in the PathToBirdsPicture field and get the desired result.

Ever since Windows introduced "My Documents", etc, I have found paths a nightmare for programming work. If anyone can tell me a reliable way to refer to the "My Documents", I'd love to hear from you.


One little bit of bad news...

It seems that, for the moment, even with ooBase 3.1, you can't build reports which draw images into the output, using just the path to the image from your database. I believe the Nice People Who Program ooBase are working on it.


Where We've Been

Well. There you have it. We've....

Best wishes to you in your database work. Please spread the word about ooBase. A visit to my freeware page (see below) would be appreciated, too!


Where You Can Go

Once you have upgraded to ooBase 3.1... and I would encourage you to do so.... and (only perhaps necessary... but a good idea anyway) upgraded to the current version of the Sun Report Builder (I was using version 1.1 in my tests)....

....You will be able to generate reports with images in them.

Another reason to do the upgrade to ooBase 3.1 is that it seems to allow you to store macros in .odb files. A Good Thing. Trust me!



Editorial Philosophy

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. There are two aspects to that: The way it is split up, and the way it is posted. See the main index to this material for more information about the way it is split up, and the way it is posted.




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 . . . . .