Access Cookbook - Ken Getz [184]
In addition to removing menus for a single form, you can set the application's default menu bar to point to an empty macro. Select Tools → Startup to set the default menu bar. In Figure 9-6, we set the default MenuBar property of the Startup dialog to mcrNoMenus, thus removing menus for all forms in the application for which custom menus were not created. Another option is to uncheck the AllowFullMenus property, which tells Access to remove all menu commands that allow users to switch to design view.
Figure 9-6. The Startup dialog allows you to customize various default properties
You can also customize the default shortcut menus using the Startup dialog by changing the AllowDefaultShortcutMenus and ShortcutMenuBar properties.
9.3. Create a Geographical Map Interface
Problem
You want to display a map and allow users to click on regions of the map. You want the form to react based on which region is clicked on. The regions aren't necessarily rectangular. How can you do this?
Solution
You can accomplish this task using a combination of bitmaps and transparent command buttons. Depending on how far from rectangular your shapes are, this task may be trivial or quite involved. By making the command buttons transparent, you make the application appear to react directly to mouse clicks on the map.
Open frmWesternUS in 09-03.MDB (Figure 9-7). This form has been created with an imported bitmap file as the background. Above each state's image on the map there's at least one command button with its Transparent property set to Yes. Figure 9-8 shows the form named frmWesternUSDesign, in which the buttons are not transparent. Here you can see the actual layout of the command buttons.
Figure 9-7. The finished map form, frmWesternUS, with transparent buttons
Figure 9-8. The same bitmap form with buttons showing
To implement similar functionality in your own forms, follow these steps:
Create a new form. Click anywhere in the detail section of the form, and select Insert Object (or use the form design toolbox to place an unbound object frame control form on the form). Once you release the mouse button, Access displays a dialog requesting information about the object. At this point, you can create a new object by launching an application such as Microsoft Paint, or you can create an object from an existing file. If you choose the latter, a Browse button will appear. Click on the Browse button to select a file (see Figure 9-9). Choose the appropriate image for the background. For the example form, use USWEST.BMP.
Figure 9-9. Browsing a file from the Insert Object dialog
Set the bitmap's SizeMode property to Clip. This disallows resizing of the bitmap, as you'll be overlaying the bitmap with command buttons.
TIP
Using Shift and Ctrl plus the arrow keys is helpful in achieving exact placement of the command buttons. Use Shift-arrow to expand and contract the size of a control one pixel at a time; use Ctrl-arrow to move the control one pixel at a time.
Overlay each defined area of the bitmap with a command button, naming each as desired. Figure 9-8 shows the completed process for the sample form. You'll find that for odd-shaped regions, you'll need to use multiple buttons, as demonstrated for Idaho, Texas, and Nevada on the map.
Select all the command buttons (hold down the Shift key and click on each). On the properties sheet, set the Transparent property to Yes, making the selected controls invisible yet active. Figure 9-10 shows the sample form in design view; note that you can still see a faint outline of each button.
Figure 9-10. The sample map form in design view
For each transparent command button, call a function, passing it the name that describes the defined area (in this example, the name of the selected U.S. state) from the button's OnClick event property. For example,