📄 ch08.htm
字号:
</OL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT> For more help on data types, search for
Data Type Summary on the Help Find tab.
<HR>
</BLOCKQUOTE>
<H2><FONT COLOR="#000077"><B>Programming: View Button Wizard Results</B></FONT></H2>
<P>You can have Access create a button and the programming behind it. (See also "Controls:
Command Button Create" in the Forms and Reports part of this book.) To see what
the programming is and modify it, you need to look at the Visual Basic <I>code</I>.
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<OL>
<B>1.</B> Open the <I>form</I> in <I>Design View</I>, right-click the command button,
and choose Build <U>E</U>vent on the shortcut menu.
<P><B>2.</B> Access opens into a <I>VBA</I> code window. The name of the command
button appears in the <I>Object</I> drop-down list at the top left, and the <TT>Click</TT>
procedure appears in the Procedure drop-down list on the right. To go to a different
object and procedure, choose from these lists.</P>
<P><B>3.</B> The procedure starts with <TT>Sub</TT> and then the procedure name.
The procedure name includes the command button's name, an underscore, and the word
<TT>Click</TT>. The procedure ends with <TT>End Sub</TT>.</P>
<P><B>4.</B> ear the top of the procedure, Access declares any variables it needs
(with <TT>Dim</TT> statements) and then uses these variables later. A common <I>variable</I>
is <TT>strDocName</TT> which holds the name of a document (usually a form or <I>report</I>)
that you are opening. You can edit the statement <TT>strDocName = "</TT>NameofDocument<TT>"</TT>
and type any document of the same type in the quotes. Another common variable is
<TT>strLinkCriteria</TT> which holds the criteria for choosing which records to display.
You can edit the statement defining the criteria as well.</P>
<P><B>5.</B> When finished viewing or modifying the procedure, click the Close (X)
button and save the form.
</OL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT> Access also has a simple error handler
in the procedure which starts with the statement <TT>On Error GoTo</TT> and then
has the label <TT>Err</TT>, underscore, and then the procedure name. Near the <TT>End
Sub</TT> statement is the <TT>Err</TT> label which shows statements that will run
if Access encounters an error. For buttons created with the wizard on the Toolbox,
Access will simply show a message box with the error description and then exit the
procedure. You can modify these statements.
<HR>
</BLOCKQUOTE>
<H2><FONT COLOR="#000077"><B>Programming: View Options</B></FONT></H2>
<P>While you are working in <I>VBA</I>, you can set viewing options to make programming
easier. These options include the size and color of fonts for the <I>code</I> window,
and whether you want to see multiple procedures at one time.
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<OL>
<B>1.</B> Choose <U>T</U>ools, <U>O</U>ptions, and click the <I>Modules</I> tab.
<P><B>2.</B> To change the text that appears in the code window, choose one of the
types of text from the Text Area drop-down list (such as Keyword Text) and change
the options for the color. You can also change the font and size of the font for
all text in the code window.</P>
<P><B>3.</B> To have Access indent the same for each line after you press tab, check
A<U>u</U>toIndent and choose the <U>T</U>ab Width. Also in the coding area, include
whether you want Access to check <I>syntax</I>, require you to declare variables,
<I>compile</I> modules automatically, and help complete statements with Aut<U>o</U>
List Members and Auto _Quick Info. Check Auto <U>D</U>ata Tips to show value of variables
as ScreenTips in Break mode.</P>
<P><B>4.</B> If you want to see one procedure after the other (instead of one procedure
per screen), check Full Module <U>V</U>iew and <U>P</U>rocedure Separator to add
a line between procedures.</P>
<P><B>5.</B> Select additional choices in the Windows Settings area to allow drag-and-drop
editing, keep the <I>Debug window</I> on top, and show icons representing breakpoints
and bookmarks in the code window. When finished making all selections, choose OK.
</OL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT> For more help on any option, click the
Help (?) button at the top right of the Options <I>dialog box</I> and click the option.
<HR>
</BLOCKQUOTE>
<H2><FONT COLOR="#000077"><B>Startup Options</B></FONT></H2>
<P>You can specify a number of options that are set when a <I>database</I> starts.
For example, you can open a particular <I>form</I>, display and customize toolbars,
and allow or disable shortcut menus. The Startup dialog box now covers almost anything
you would do with the AutoExec <I>macro.</I> (See also "Macros: Create in Design
Window.") If you are going to create a run-time version of Access with the Developer's
Tools, fill out the options on this dialog box.
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<OL>
<B>1.</B> Choose <U>T</U>ools, Start<U>u</U>p with a database open.
<P><B>2.</B> Type the text you want to appear in the title bar in A_pplication Title,
and choose the icon you want in the title bar by clicking the Application <U>I</U>con
button.</P>
<P><B>3.</B> Choose the <U>M</U>enu Bar and <U>S</U>hortcut Menu Bar you want at
startup. Choose the check boxes determining which Access default menus and toolbars
should appear.</P>
<P><B>4.</B> From the Display <U>F</U>orm drop-down list, choose the form you want
to appear at startup and choose whether you want the <I>Database window</I> and <I>status
bar</I> to be visible or hidden.</P>
<P><B>5.</B> Click the Advanced button and choose whether you want to see the <I>code</I>
after an error is made and allow the following keys to be available: F11 (Database
window), Ctrl+G (<I>Debug window</I>), Ctrl+F11 (toggle between menu from step 3
and built-in menu), and Ctrl+Break (stop procedures). Choose OK when finished setting
all options.
</OL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT> If you don't want to have these startup
options run, hold down Shift when you open the database file.
<HR>
</BLOCKQUOTE>
<H2><FONT COLOR="#000077"><B>Toolbar: Create Custom</B></FONT></H2>
<P>When you design a <I>form</I> or <I>report</I>, you can display a toolbar different
than the default toolbar for that <I>object</I>. You can also set a non-default toolbar
to appear for your entire application. The first step is to create the toolbar.
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<OL>
<B>1.</B> Choose <U>V</U>iew, <U>T</U>oolbars, <U>C</U>ustomize; click the Tool<U>b</U>ars
tab; and choose the <U>N</U>ew <I>command button</I>.
<P><B>2.</B> Type the name of the toolbar in the New Toolbar <I>dialog box</I> and
choose OK. If necessary, drag the title bar of Customize dialog box to see the new
small toolbar.</P>
<P><B>3.</B> Click the <U>C</U>ommands tab of the Customize dialog box. Choose one
of the names in the Cate_gories list and drag one of the items from the Comman<U>d</U>s
list onto your toolbar. To add a <I>macro</I> to a button, choose All Macros from
the Cate_gories list and drag a macro from the Comman<U>d</U>s list.</P>
<P><B>4.</B> To add a Visual Basic function procedure to a button, drag any item
from the Comman<U>d</U>s list. Right-click the button on the new toolbar and choose
<U>P</U>roperties. Type a name for the button in the <U>C</U><I>aption</I> box, and
type text for a <U>T</U>oolTip if desired. In the <U>O</U>n Action box, type <B>=functionname()</B>
where <I>functionname</I> is the name of your function (you cannot use a sub procedure).</P>
<P><B>5.</B> To change the image of the button, right-click the button, choose Change
<U>B</U>utton Image, and pick a picture.</P>
<P><B>6.</B> Repeat Steps 3-5 for all the buttons on your toolbar, and choose the
Close button on the Customize dialog box when finished.
</OL>
<P>To delete a button on your customized toolbar, drag it off the toolbar while the
Customize dialog box is visible. To view or hide the toolbar, see also "Toolbars:
Display."
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>TIP:</B></FONT> While customizing a toolbar you can also
right-click the button and choose <U>E</U>dit Button Image (and draw your own image)
or <U>C</U>opy Button Image from another button and then return to the button and
choose <U>P</U>aste Button Image. Another alternative is to type text in the Name
box and choose Text <U>O</U>nly.
<HR>
</P>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT> There are some toolbar properties you can
change. On the Customize dialog box, choose the <U>P</U>roperties command button
and decide if you want to allow customizing, moving, resizing, and show/hide for
your toolbar.
<HR>
</BLOCKQUOTE>
<H2><FONT COLOR="#000077"><B>Toolbars: Display</B></FONT></H2>
<P>Generally you should let Access display the toolbars that are the default for
each part of the program (the <I>Table</I> Design toolbar in Table <I>Design View</I>,
<I>Form</I> Design and Form/<I>Report</I> Formatting toolbars in Form Design View,
and so forth). If you display too many toolbars, it is difficult to tell which buttons
you need and you have much less space as your work area. However, you might want
to display the Web toolbar or custom toolbars you've created.
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<OL>
<B>1.</B> Choose <U>V</U>iew, <U>T</U>oolbars, <U>C</U>ustomize and click the Tool<U>b</U>ars
tab on the Customize <I>dialog box</I>.
<P><B>2.</B> Place a check mark by each toolbar you want to see.</P>
<P><B>3.</B> If a toolbar appears when it should not, select the toolbar name and
choose the <U>R</U>eset button.</P>
<P><B>4.</B> If you want to see large buttons on the toolbars, show ScreenTips (names
of tools), or include shortcut keys with the ScreenTips, click the <U>O</U>ptions
tab and make your choices. Choose Close when finished.
</OL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT> You can also use the <I>macro</I> action
Show Toolbar to display or hide a toolbar or type in a <I>VBA</I> procedure <B>DoCmd.ShowToolbar
"<I>Toolbarname</I>", <I>ShowConstant</I></B>. Type the name of the toolbar
in quotes in place of <I>Toolbarname</I>. Type one of the following Access constants
in place of <I>ShowConstant</I>: <B>acToolbarNo</B>, <B>acToolbarYes</B>, or <B>acToolbarWhereApprop</B>.
The default is <TT>acToolbarYes</TT> if you leave off this option.
<HR>
</BLOCKQUOTE>
</TD>
</TR>
<TR>
<TD WIDTH="80"></TD>
<TD WIDTH="520">
<P ALIGN="CENTER"><A HREF="index.htm"><IMG
SRC="../buttonart/btoc.gif" WIDTH="41" HEIGHT="41" ALIGN="BOTTOM" ALT="TOC" BORDER="0"
NAME="toc8"></A><A HREF="ch07.htm"><IMG
SRC="../buttonart/bback.gif" WIDTH="41" HEIGHT="41" ALIGN="BOTTOM" ALT="BACK" BORDER="0"
NAME="toc6"></A><A HREF="ch09.htm"><IMG
SRC="../buttonart/bforward.gif" WIDTH="41" HEIGHT="41" ALIGN="BOTTOM" ALT="FORWARD"
BORDER="0" NAME="toc7"></A><A HREF="index.htm"><IMG
SRC="../buttonart/bhome.gif" WIDTH="41" HEIGHT="41" ALIGN="BOTTOM" ALT="HOME" BORDER="0"
NAME="toc5"></A><BR>
<BR>
<IMG SRC="../buttonart/corp.gif" WIDTH="284" HEIGHT="45" ALIGN="BOTTOM" BORDER="0"></P>
<P><BR>
<FONT COLOR="#000000">©</FONT><A HREF="copy.htm"><FONT COLOR="#000000">Copyright</FONT></A><FONT
COLOR="#000000">, Macmillan Computer Publishing. All rights reserved.</FONT>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -