[AccessD] When a query refers to a control on a form which is not open - how to supply a default?

Kenneth Ismert kismert at gmail.com
Wed Jun 2 14:16:27 CDT 2010


All,

Sorry about my earlier post -- hit 'Send' instead of 'Save' ...

I think the larger point John, Doug, and Gustav are making here is that it
is better to coordinate queries with forms and reports using functions, not
direct control references.

The function I proposed to Dale Kalsow also works here:

Public Function Jobs_Date(Optional vValue As Variant) As Variant
    Static vParm As Variant
    If Not IsMissing(vValue) Then
        vParm = vValue
    ElseIf IsEmpty(vParm) Then
        vParm = Null     '  default
    End If
    Jobs_Date = vParm
End Function

This implements a single named parameter for sharing between queries, forms
and reports.

Like John's example, it is a 'push/pull' function. When you supply a value,
it pushes the value into the function. When you omit the value, it returns
the current value or the default.

John's function is more compact, in that one function can handle any number
of named values. But it sacrifices the ability to customize default values,
and can't detect when you call it with an improper parameter name.

My function lets you customize default values, and do type-checking on the
input. It also either works (you type the function name right) or it
doesn't. The drawback is you have to define a function for each global
parameter in your application.

Either approach works fine, depending on your needs.

Access applications are easier to develop, and more trouble-free, if you use
some system of global functions to coordinate queries with forms and
reports.

-Ken



More information about the AccessD mailing list