Set Options From Visual Basic: View Tab
Set Options From Visual Basic: View Tab
You can use the SetOption and GetOption methods to set and return option values in the
Options dialog box from code. To view the Options dialog box, click Options on the Tools
menu.
The following tables list the names of all options that can be set or returned from code and the
tabs on which they can be found in the Options dialog box, followed by the corresponding
string argument that you must pass to the SetOption or GetOption method.
Notes
If your database may run on a version of Microsoft Access for a language other than the one
in which you created it, then you must supply the arguments for the GetOption and
SetOption methods in English.
Some options are available only within a Microsoft Access database (.mdb) or Access project
(.adp).
View Tab
Option text String argument
Show, Status bar Show Status Bar
Show, Startup Task Pane Show Startup Dialog Box
Show, New object shortcuts Show New Object Shortcuts
Show, Hidden objects Show Hidden Objects
Show, System objects Show System Objects
Show, Windows in Taskbar ShowWindowsInTaskbar
Show in Macro Design, Names column Show Macro Names Column
Show in Macro Design, Conditions column Show Conditions Column
Click options in database window Database Explorer Click Behavior
General Tab
Option text String argument
Print margins, Left margin Left Margin
Print margins, Right margin Right Margin
Print margins, Top margin Top Margin
Print margins, Bottom margin Bottom Margin
Use four-year digit year formatting, This database Four-Digit Year Formatting
Use four-year digit year formatting, All databases Four-Digit Year Formatting All
Databases
Name AutoCorrect, Track name AutoCorrect info Track Name AutoCorrect Info
Name AutoCorrect, Perform name AutoCorrect Perform Name AutoCorrect
Name AutoCorrect, Log name AutoCorrect changes Log Name AutoCorrect Changes
Recently used file list Enable MRU File List
Recently used file list, (number of files) Size of MRU File List
Provide feedback with sound Provide Feedback with Sound
Compact on Close Auto Compact
New database sort order New Database Sort Order
Remove personal information from file properties on
Remove Personal Information
save
Default database folder Default Database Directory
Edit/Find Tab
Option text String argument
Default find/replace behavior Default Find/Replace Behavior
Confirm, Record changes Confirm Record Changes
Confirm, Document deletions Confirm Document Deletions
Confirm, Action queries Confirm Action Queries
Show list of values in, Local indexed fields Show Values in Indexed
Show list of values in, Local nonindexed fields Show Values in Non-Indexed
Show list of values in, ODBC fields Show Values in Remote
Show list of values in, Records in local snapshot Show Values in Snapshot
Show list of values in, Records at server Show Values in Server
Don't display lists where more than this number of records
Show Values Limit
read
Datasheet Tab
Option text String argument
Default colors, Font Default Font Color
Default colors, Background Default Background Color
Default colors, Gridlines Default Gridlines Color
Default gridlines showing, Horizontal Default Gridlines Horizontal
Default gridlines showing, Vertical Default Gridlines Vertical
Default column width Default Column Width
Default font, Font Default Font Name
Default font, Weight Default Font Weight
Default font, Size Default Font Size
Default font, Underline Default Font Underline
Default font, Italic Default Font Italic
Default cell effect Default Cell Effect
Show animations Show Animations
Show Smart Tags on Datasheets Show Smart Tags on Datasheets
Keyboard Tab
Option text String argument
Move after enter Move After Enter
Behavior entering field Behavior Entering Field
Arrow key behavior Arrow Key Behavior
Cursor stops at first/last field Cursor Stops at First/Last Field
Auto commit Ime Autocommit
Datasheet IME control Datasheet Ime Control
Tables/Queries Tab
Option text String argument
Table design, Default field sizes - Text Default Text Field Size
Table design, Default field sizes - Number Default Number Field Size
Table design, Default field type Default Field Type
Table design, AutoIndex on Import/Create AutoIndex on Import/Create
Query design, Show table names Show Table Names
Query design, Output all fields Output All Fields
Query design, Enable AutoJoin Enable AutoJoin
Query design, Run permissions Run Permissions
Query design, SQL Server Compatible Syntax (ANSI 92) -
ANSI Query Mode
This database
Query design, SQL Server Compatible Syntax (ANSI 92) -
ANSI Query Mode Default
Default for new databases
Query design, Query design font, Font Query Design Font Name
Query design, Query design font, Size Query Design Font Size
Show Property Update Options
Show Property Update Options buttons
buttons
Forms/Reports Tab
Option text String argument
Selection behavior Selection Behavior
Form template Form Template
Report template Report Template
Always use event procedures Always Use Event Procedures
Show Smart Tags on Forms Show Smart Tags on Forms
Show Windows Themed Controls on Forms Themed Form Controls
Advanced Tab
Option text String argument
DDE operations, Ignore DDE requests Ignore DDE Requests
DDE operations, Enable DDE refresh Enable DDE Refresh
Default File Format Default File Format
Default open mode Default Open Mode for Databases
Command-line arguments Command-Line Arguments
OLE/DDE timeout (sec) OLE/DDE Timeout (sec)
Default record locking Default Record Locking
Refresh interval (sec) Refresh Interval (sec)
Number of update retries Number of Update Retries
ODBC refresh interval (sec) ODBC Refresh Interval (sec)
Update retry interval (msec) Update Retry Interval (msec)
Open databases using record-level locking Use Row Level Locking
Pages Tab
Option text String argument
Default Designer Properties, Section Indent Section Indent
Default Designer Properties, Alternate Row Color Alternate Row Color
Default Designer Properties, Caption Section Style Caption Section Style
Default Designer Properties, Footer Section Style Footer Section Style
Default Database/Project Properties, Use Default Page Folder Use Default Page Folder
Default Database/Project Properties, Default Page Folder Default Page Folder
Default Database/Project Properties, Use Default Connection File Use Default Connection File
Default Database/Project Properties, Default Connection File Default Connection File
Spelling Tab
Option text String argument
Dictionary Language Spelling dictionary language
Add words to Spelling add words to
Spelling suggest from main dictionary
Suggest from main dictionary only
only
Ignore words in UPPERCASE Spelling ignore words in UPPERCASE
Ignore words with numbers Spelling ignore words with number
Ignore Internet and file addresses Spelling ignore Internet and file addresses
Language-specific, German: Use post-reform rules Spelling use German post-reform rules
Language-specific, Korean: Combine aux verb/adj. Spelling combine aux verb/adj
Language-specific, Korean: Search misused word
Spelling use auto-change list
list
Language-specific, Korean: Process compound
Spelling process compound nouns
nouns
Language-specific, Hebrew modes Spelling Hebrew modes
Language-specific, Arabic modes Spelling Arabic modes
International Tab
Option text String argument
Right-to-Left, Default direction Default direction
Right-to-Left, General alignment General alignment
Right-to-Left, Cursor movement Cursor movement
Use Hijri Calendar Use Hijri Calendar
Note If you are developing a database application, add-in, library database, or referenced
database, make sure that the Error Trapping option is set to 2 (Break On Unhandled
Errors) when you have finished debugging your code.
The value that you pass to the SetOption method as the setting argument depends on which
type of option you are setting. The following table establishes some guidelines for setting
options.
The Load event occurs when a form is opened and its records are displayed.
Remarks
To run a macro or event procedure when these events occur, set the OnLoad property to the
name of the macro or to [Event Procedure].
By running a macro or an event procedure when a form's Load event occurs, you can specify
default settings for controls, or display calculated data that depends on the data in the form's
records.
By running a macro or an event procedure when a form's Unload event occurs, you can verify
that the form should be unloaded or specify actions that should take place when the form is
unloaded. You can also open another form or display a dialog box requesting the user's name
to make a log entry indicating who used the form.
When you first open a form, the following events occur in this order:
If you're trying to decide whether to use the Open or Load event for your macro or event
procedure, one significant difference is that the Open event can be canceled, but the Load
event can't. For example, if you're dynamically building a record source for a form in an event
procedure for the form's Open event, you can cancel opening the form if there are no records
to display.
When you close a form, the following events occur in this order:
The Unload event occurs before the Close event. The Unload event can be canceled, but the
Close event can't.
Note When you create macros or event procedures for events related to the Load event, such
as Activate and GotFocus, be sure that they don't conflict (for example, make sure you don't
cause something to happen in one macro or procedure that is canceled in another) and that
they don't cause cascading events.
Macro
You can use a Load macro to carry out actions for the controls or records on a form after the
form opens. For example, you can specify default settings for controls.
You can use the CancelEvent action in an Unload macro to cancel unloading of the records.
This also cancels closing of the form.
If a form's Unload macro carries out a CancelEvent action, you won't be able to close the
form. You must either correct the condition that caused the CancelEvent action to be carried
out or open the macro and delete the CancelEvent action. If the form is modal, you won't be
able to open the macro or work in any other windows in the application.
Example
The following example displays the current date in the form's caption when the form is
loaded.
Open Event
See AlsoApplies ToExampleSpecifics
The Open event occurs when a form is opened, but before the first record is displayed. For
reports, the event occurs before a report is previewed or printed.
Cancel The setting determines if the opening of the form or report occurs. Setting the
Cancel argument to True (1) cancels the opening of the form or report.
Remarks
To run a macro or event procedure when these events occur, set the OnOpen property to the
name of the macro or to [Event Procedure].
By running a macro or an event procedure when a form's Open event occurs, you can close
another window or move the focus to a particular control on a form. You can also run a macro
or an event procedure that asks for information needed before the form or report is opened or
printed. For example, an Open macro or event procedure can open a custom dialog box in
which the user enters the criteria for the set of records to display on a form or the date range
to include for a report.
The Open event doesn't occur when you activate a form that's already open for example,
when you switch to the form from another window in Microsoft Access or use the OpenForm
action in a macro to bring the open form to the top. However, the Activate event does occur in
these situations.
When you open a form based on an underlying query, Microsoft Access runs the underlying
query for the form before it runs the Open macro or event procedure. However, when you
open a report based on an underlying query, Microsoft Access runs the Open macro or event
procedure before it runs the underlying query for the report. This enables the user to specify
criteria for the report before it opens for example, in a custom dialog box you display when
the Open event occurs.
If your application can have more than one form loaded at a time, use the Activate and
Deactivate events instead of the Open event to display and hide custom toolbars when the
focus moves to a different form.
The Open event occurs before the Load event, which is triggered when a form is opened and
its records are displayed.
When you first open a form, the following events occur in this order:
The Close event occurs after the Unload event, which is triggered after the form is closed but
before it is removed from the screen.
When you close a form, the following events occur in this order:
When the Close event occurs, you can open another window or request the user's name to
make a log entry indicating who used the form or report.
If you're trying to decide whether to use the Open or Load event for your macro or event
procedure, one significant difference is that the Open event can be canceled, but the Load
event can't. For example, if you're dynamically building a record source for a form in an event
procedure for the form's Open event, you can cancel opening the form if there are no records
to display. Similarly, the Unload event can be canceled, but the Close event can't.
Macro
You can use the CancelEvent action in an Open macro to cancel opening of the form or report.
You can't use the CancelEvent action in a Close macro to cancel the Close event. However,
you can use the CancelEvent action in a macro that runs when the Unload event occurs on a
form. This cancels closing of the form.
If you want to refer to controls from an Open macro, you must first move the focus to the
appropriate control or record. For example, to use a SetValue action in an Open macro to set
the value of a control on a form, you must first use the GoToControl or GoToRecord action to
access the control or the record containing the control.
Example
The following example shows how you can cancel the opening of a form when the user clicks
a No button. A message box prompts the user to enter order details. If the user clicks No, the
Order Details form isn't opened.
FindRecord Action
You can use the FindRecord action to find the first instance of data that meets the criteria
specified by the FindRecord arguments. This data can be in the current record, in a succeeding
or prior record, or in the first record. You can find records in the active table datasheet, query
datasheet, form datasheet, or form.
Setting
The FindRecord action has the following arguments.
Action
Description
argument
Specifies the data you want to find in the record. Enter the text, number, or date
you want to find or type an expression, which is preceded by an equal sign (=), in
Find What
the Find What box in the Action Arguments section of the Macro window. You
can use wildcard characters. This is a required argument.
Specifies where the data is located in the field. You can specify a search for data
in any part of the field (Any Part Of Field), for data that fills the entire field
Match
(Whole Field), or for data located at the beginning of the field (Start Of Field).
The default is Whole Field.
Specifies whether the search is case-sensitive. Click Yes (conduct a case-
Match Case sensitive search) or No (search without matching uppercase and lowercase letters
exactly). The default is No.
Specifies whether the search proceeds from the current record up to the
beginning of the records (Up); down to the end of the records (Down); or down
Search
to the end of the records and then from the beginning of the records to the current
record, so all records are searched (All). The default is All.
Specifies whether the search includes formatted data. Click Yes (Microsoft
Access searches for the data as it's formatted and displayed in the field) or No
(Access searches for the data as it's stored in the database, which isn't always the
same as it's displayed). The default is No.
You can use this feature to restrict the search to data in a particular format. For
example, click Yes and type 1,234 in the Find What argument to find a value of
1,234 in a field formatted to include commas. Click No if you want to type 1234
to search for the data in this field.
To search for dates, click Yes to find a date exactly as it's formatted, such as 09-
Search As March-2001. If you click No, enter the date for the Find What argument in the
Formatted format that is set in the regional settings in Windows Control Panel. This format
is shown in the Short date format box found on the Date tab in the regional
settings. For example, if the Short date format box is set to M/d/yy, you can
enter 3/9/01, and Access will find all entries in a Date field that correspond to
March 9, 2001, regardless of how this field is formatted.
Note The Search As Formatted argument takes effect only if the current field is
a bound control, the Match argument is set to Whole Field, the Only Current
Field argument is set to Yes, and the Match Case argument is set to No.
If you set Match Case to Yes or Only Current Field to No, you must also set
Search As Formatted to Yes.
Specifies whether the search is confined to the current field in each record or
Only
includes all fields in each record. The current field search is faster. Click Yes
Current
(confine the search to the current field) or No (search in all fields in each record).
Field
The default is Yes.
Specifies whether the search starts at the first record or at the current record.
Find First Click Yes (start at the first record) or No (start at the current record). The default
is Yes.
Remarks
When a macro runs the FindRecord action, Access searches for the specified data in the
records (the order of the search is determined by the setting of the Search argument). When
Access finds the specified data, the data is selected in the record.
The FindRecord action is equivalent to clicking Find on the Edit menu, and its arguments are
the same as the options in the Find In Field dialog box, available by clicking Find on the
Edit menu. If you set the FindRecord arguments in the Macro window and then run the
macro, you'll see the corresponding options selected in the Find In Field dialog box when
you click Find.
Access retains the most recent FindRecord arguments during a database session so that you
don't need to enter the same criteria repeatedly as you perform subsequent FindRecord
operations. If you leave an argument blank, Access uses the most recent setting for the
argument, as set either by a previous FindRecord action or in the Find In Field dialog box.
When you want to find a record by using a macro, use the FindRecord action, not the
RunCommand action with its argument set to run the Find command.
Note While the FindRecord action corresponds to Find on the Edit menu for tables, queries,
and forms, it doesn't correspond to Find on the Edit menu in the Code window. You can't use
the FindRecord action to search for text in modules.
If the currently selected text is the same as the search text at the time the FindRecord macro
action is carried out, the search begins immediately following the selection in the same field
as the selection, and in the same record. Otherwise the search begins at the start of the current
record. This enables you to find multiple instances of the same search criteria that might
appear in a single record.
However, note that if you use a command button to run a macro containing the FindRecord
action, the first instance of the search criteria will be found repeatedly. This behavior occurs
because clicking the command button removes the focus from the field containing the
matching value. The FindRecord action will then begin searching from the start of the record.
To avoid this problem, run the macro by using a technique that doesn't change the focus, such
as a custom toolbar button or a key combination defined in an AutoKeys macro, or set the
focus in the macro to the field containing the search criteria before you carry out the
FindRecord action.
Security Avoid using the SendKeys statement or an AutoKeys macro with sensitive or
confidential information. A malicious user could intercept the keystrokes and compromise the
security of your computer and data.
The same behavior also occurs if you use a command button to run a macro containing the
FindNext action.
To run the FindRecord action in Visual Basic, use the FindRecord method of the DoCmd
object.
OpenDatabase Method
Opens a specified database in a Workspace object and returns a reference to the
Database object that represents it.
Syntax
Part Description
database An object variable that represents the Database object that you want
to open.
dbname A String that is the name of an existing Microsoft Jet database file, or
the data source name (DSN) of an ODBC data source. See the Name
property for more information about setting this value.
options Optional. A Variant that sets various options for the database, as
specified in Settings.
read-only Optional. A Variant (Boolean subtype) value that is True if you want
to open the database with read-only access, or False (default) if you
want to open the database with read/write access.
Settings
For Microsoft Jet workspaces, you can use the following values for the options argument.
Setting Description
For ODBCDirect workspaces, the options argument determines if and when to prompt the
user to establish the connection. You can use one of the following constants.
Constant Description
Remarks
If it refers to a database that is already open for exclusive access by another user,
an error occurs.
The connect argument is expressed in two parts: the database type, followed by a
semicolon (;) and the optional arguments. You must first provide the database type, such
as "ODBC;" or "FoxPro 2.5;". The optional arguments follow in no particular order,
separated by semicolons. One of the parameters may be the password (if one is
assigned). For example:
To close a database, and thus remove the Database object from the Databases
collection, use the Close method on the object.
Note When you access a Microsoft Jet-connected ODBC data source, you can improve
your application's performance by opening a Database object connected to the ODBC
data source, rather than by linking individual TableDef objects to specific tables in the
ODBC data source.