Once you've learned how to use Microsoft Access to build forms for entering and querying data (See Uplink, April 2000), you can link them to create a program for sharing data with other reporters.
In this exercise, we'll build upon the chronology we created as part of the April Tech Tip by linking it to a startup screen. If you need a copy of the database we used last month, you can download it from the NICAR web site (www.nicar.org).
Before getting into the how-to, it's important to understand the structure of an Access database. An Access database is a container for objects. Tables, forms, queries and reports are the most commonly used objects. Access also includes macros (sequences of defined actions) and modules (Visual Basic code) to help you control programs. We'll use macros, which are powerful enough for our program.
Create the startup screen
Begin by opening the program and creating a new form. Once you've opened the database, click on the Forms tab, then New. Make sure Design View is selected, then click OK and a blank form appears. This blank form is your canvas for creating a startup screen. By setting the form's properties, you can change the color. By clicking buttons on the toolbar you can add text and graphics.
An Access database is a container for objects. Tables, forms, queries and reports are the most commonly used objects.
First, let's make sure that this startup screen launches whenever we start the program. Close the form and save it; call it Welcome. Now we will use a macro to make it the startup screen. Click on the Macros tab, then pick New. The Macro design grid opens.
In the Action column we well specify what we want the macro to do.
Click on the drop down arrow and scroll down the list until you find OpenForm. Select it. Then, in the Action Arguments section on the bottom part of the screen, click in the Form Name box and select Welcome from the list. Keep all other settings as they are. Close the macro design grid and name it AutoExec. When Access opens a database, it looks to see the whether there is an AutoExec macro. If there is, Access runs it. Test your macro by closing your database, then opening it again.
Open the Welcome form again by clicking on the Forms tab, highlighting Welcome and clicking the Design button. Let's modify the form's appearance.
Change the color by clicking once anywhere on the form with the right mouse button to get the pop-up menu. Select Properties. Click the Format tab to get a list of the formatting properties you can set. Click on Back Color, then the ellipsis button to get a color palette. Select a color.
Now we will set the properties of the form to remove some of the frills. Click once on the form select box, the small square located at the intersection of the rulers at the top left corner. Click the right mouse button to get the pop-up menu and select Properties. Click on the Format tab to set the following properties:
Views allowed: Form Scroll bars: Neither Record selectors: No Navigation buttons: No Control Box: No Close the form properties box.
Give the form a title by clicking on the Label button on the toolbox, then clicking on the form where you would like the title to go. Type "Digging for data" without the quotation marks, then hit Enter. Look at the text on your form. Obviously, this could look better. We can change the text properties by right-clicking the text, then clicking Properties in the pop-up menu. Use the Fore Color, Font Name, Font Size, Font Weight, Font Italic, Font Underline and Text Align properties to modify your label's appearance.
Now add a picture to your form. I grabbed the logo from NICAR's web site. Here's how I added it to the form: First I clicked on the Image button on the toolbox. Then, using the mouse, I drew a frame for the logo by left clicking on the form, dragging diagonally and releasing the button. I added the logo by finding the graphic file on my computer.
Button up
So far, all we've done is work on the window dressing. It's time to put the form to work with some buttons.
The first button will shut Access down. Click on the Command Button item on the toolbox, then use the cross to draw the shape of your button, just as you did to add a frame for your graphic. When you release the mouse button, the Command Button Wizard starts. The wizard makes creating command buttons a snap. In the Categories box, pick Application. In the Actions box, pick Quit Application. Then click on the Next button. In the next step, select the type of button you want, then click Next. At the next screen, click Finish.
Test your command button by switching to form view, then clicking it to see what happens. Start the database again and open the Welcome form in design view, where we'll add a button that minimizes the startup screen and opens the Chronology form. We will link the button to a new macro that will manipulate the forms.
Click on the Macros tab and select New. In the first Action cell, click Minimize. This minimizes the active window (the Welcome form, in our case). In the second Action cell, select Open Form. In the Action Arguments section at the bottom of the screen, select Chronology in the Form Name option. Close the macro design view and give it a logical name, such as open_chrono.
Go back to the Welcome form in design view. Add a command button using the Command Button item on the toolbox. Draw a button on the form using your mouse and release the button to launch the Command Button Wizard. In the Categories box, select Miscellaneous, and in the Actions box select Run Macro and click the Next button. Select "open_chrono" as the macro to run and click the Next button. Design the button by clicking on Text and typing "Chronology" without the quotation marks. Click Next, then Finish.
Test your work by switching to the Welcome form's form view. Click on the Chronology button and see what happens. The Welcome form should shrink and the Chronology form should open. Now click on the Close button at the bottom of the Chronology form.
The Chronology form closes and the Welcome form remains minimized. We will add a macro and a button to make sure the Chronology form also re-opens the Welcome form. Create a new macro by clicking on the Macros tab, then clicking New. In the first Actions cell, select Close. In Action Arguments section, select Form as the Object Type and Chronology as the Object Name. In the second Actions cell, select Open Form. In the Action Arguments section, pick Welcome as the form name. Close the macro design view and save this as close chrono.
Now we need to link the macro to a new button on the Chronology form. Open the Chronology form in design view. Click on its close button and then hit the delete key to get rid of it. Create a new button by clicking on the Command Button item on the toolbox and drawing the outline of the button using the mouse. When you release the mouse button, the Command Button Wizard starts. Pick Miscellaneous from Categories and Run Macro from Actions and click Next. Then select "close_chrono" from the list of macros and click Next. Select the style of button you want and click Next, then Finish. Close your form and save it.
It's time to see how everything works together. Close Access and open the database again. Use the command buttons to navigate between the Welcome form and Chronology form.
There's more to know about creating programs to share data (such as how to secure the program on a network). But using the principles in this Tech Tip and April's Tech Tip, you can add all the tables you need and build more forms for adding and querying data.
David Herzog can be reached by e-mail at david_herzog@projo.com.