Access Cookbook - Ken Getz [286]
The next line of code does the work:
dapPage.MSODSC.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strConnectionDB
ConnectionString is a property of the DataSource control that is automatically included on every bound DAP. In code, the DataSource control is called MSODSC.
Once the string has been changed, the code saves and closes the DAP and moves on to the next page object:
DoCmd.Close acDataAccessPage, dapPage.Name, acSaveYes
Finally, after the code has iterated through all the pages, the cleanup work is done. The code turns the hourglass off, sets warnings on, and turns screen painting on:
' Turn on warnings and screen painting.
DoCmd.Hourglass False
DoCmd.SetWarnings True
Application.Echo True
If any part of the code fails, the function returns a False value.
TIP
It would seem that you could simply use the name of the database (without its path) if it was in the same folder as the page file (the .htm file). Unfortunately, this doesn't work. Therefore, you'll need to update the connection string information any time you move your database and page files to a new location.
13.7. Change the Default Settings for New DAPs
Problem
You don't like the default colors for the background of the caption and footer section, or for the alternate row in a tabular page. You also wish you didn't have to change the ConnectionFile property for every page you create to point to the same .udl file.
Solution
Access's Tools → Options dialog now includes a Pages page where you can set defaults for any new pages you create. Changing the defaults will have no effect on existing pages.
To see how the color options affect the look of your new pages, follow these steps:
Create a new DAP. Add a table to the page and request a Tabular layout.
Switch to page view. Unless your defaults have already been changed, you'll see a caption with a steelblue background, and every other row will have a whitesmoke background.
Close the page.
Select Tools Options from the main Access menu. Click the Pages tab. You'll see the dialog shown in Figure 13-21.
Figure 13-21. The default Pages options
Change the alternate row color to thistle.
Edit the Caption Section Style text box to use plum instead of whitesmoke as the background color. The dialog will now look like Figure 13-22.
Figure 13-22. The Pages options after editing
Click the OK button to accept the changes and close the dialog.
Create a new page. Add a table to the page and request a Tabular layout.
Switch to page view. You'll now see a caption with a thistle background, and every other row will have a plum background.
Discussion
We used the Options dialog to change the look of two sections. All the options for pages are listed in Table 13-2. You can play around with these until you find the look you want.
Table 13-2. Page options
Option
Description
Section Indent
Defines the distance between the section and the page margin.
Alternate Row Color
Defines the color for every other row in a tabular page.
Caption Section Style
Uses standard HTML syntax to define the style for the caption section, where it exists.
Footer Section Style
Uses standard HTML syntax to define the style for the footer section, where it exists.
Use Default Page Folder
Specifies whether to store all pages (the actual .htm files) in a folder other than the folder of the current database.
Default Page Folder
If Use Default Page Folder is checked, specifies the folder where .htm files should be stored.
Use Default Connection File
Specifies whether to use a connection file ( .udl or .odc) for all new pages.
Default Connection File
If Use Default Connection File is checked, specifies the connection file to be used.
13.8. Use Parameters Set in One DAP to Open Another
Problem
In Access, every report your users run starts with a dialog prompting them for input parameters, such as the requested timeframe for the report. How can you do the same thing with DAPs? You'd like