Microsoft Access 2010 Bible

(Rick Simeone) #1

Part III: More-Advanced Access Techniques


704


The relevant properties of this dialog box are outlined in Table 19.2.

TABLE 19.2

Property Settings for Dialog Forms


Property Setting Purpose

ScrollBars Neither Not needed.
NavigationButtons No Not needed.
PopUp Yes Keeps the form on top of other forms in the application.
Modal Yes Prevents the user from working with another part of the application
until the dialog box is removed.
RecordSelectors No Not needed.
BorderStyle Dialog Specifies wide borders that can’t be resized. Also removes Minimize
and Maximize buttons.
ShortcutMenu No Not needed.

After these changes have been made, you have a form that’s always on top of the user’s work and
won’t leave the screen until the user clicks the Run Query or Cancel button.

There are a couple of rules you should follow when constructing dialog boxes. These rules ensure
that your dialog boxes conform with the generally accepted behavior for Windows dialog boxes.

Composing the SQL statement
A temporary querydef object is created when the user clicks the Run Query button. Although
you’re simply opening the query on the screen, the temporary query could just as easily serve as
the RecordSource of a form or report.

Private Sub cmdRunQuery_Click()
Dim db As DAO.Database
Dim QD As DAO.QueryDef
Dim where As Variant
Set db = CurrentDb
‘Delete existing dynamic query, trap error if it does not exist.
On Error Resume Next
db.QueryDefs.Delete (“MyQuery”)
On Error GoTo 0
‘ Note single quotes surrounding text
‘ fields [Ship Country]and [Customer ID].
‘ Note NO single quotes surrounding
‘ numeric field [Employee ID].
where = Null
Free download pdf