restrictions on expression in properties of controls in Access

P

Peter J. Veger

Again and again I stumble against the restrictions on expressions that can
be put into properties of controls
(e.g. in a Control Source: "=formmodule.function(parameters)"

It appears to be impossible to use (public)
user-defined-types/variables/functions in class/form/report modules.

The real problem is, I can nowhere find a clear, complete description of
these restriction: do you really have to find that out by trial and error,
or is there somewhere such a description?

peter veger, best, netherlands
 
L

Larry Daugherty

Read up on the scope rules for variables. Then, adopt one of the standard
naming conventions, the Reddick convention is popular. Then there may be
some trial and error as you are applying what you've learned. The Debugger
and the Immediate window can be a great help in checking your assumptions.

HTH
 
P

Peter J. Veger

Larry Daugherty said:
Read up on the scope rules for variables. Then, adopt one of the standard
naming conventions, the Reddick convention is popular. Then there may be
some trial and error as you are applying what you've learned. The
Debugger
and the Immediate window can be a great help in checking your assumptions.

I am looking for:
- a specification of the rules
- for expressions that are used to specify the properties of controls
- in the design forms (of tables, forms and reports)
not for use in the VBA in modules (whatever: standard, class, form/report
....)

To give another example: in the form through which you specify a table, it
is not possible to give a date/time field a default value of Date() or Date

peter veger, best, netherlands
 
D

Douglas J. Steele

Peter J. Veger said:
I am looking for:
- a specification of the rules
- for expressions that are used to specify the properties of controls
- in the design forms (of tables, forms and reports)
not for use in the VBA in modules (whatever: standard, class, form/report
...)

To give another example: in the form through which you specify a table, it
is not possible to give a date/time field a default value of Date() or
Date

It's possible to set a default value of Date (or Now) for fields. What
happens when you try?
 
L

Larry Daugherty

Hi Peter,

some prose from Access 97 Help:

Understanding Scope and Visibility

See Also Specifics



Scope refers to the availability of a variable, constant, or procedure for
use by another procedure. There are three scoping levels: procedure-level,
private module-level, and public module-level.
You determine the scope of a variable when you declare it. It's a good idea
to declare all variables explicitly to avoid naming-conflict errors between
variables with different scopes.

Defining Procedure-Level Scope

A variable or constant defined within a procedure is not visible outside
that procedure. Only the procedure that contains the variable declaration
can use it. In the following example, the first procedure displays a message
box that contains a string. The second procedure displays a blank message
box because the variable strMsg is local to the first procedure.

Sub LocalVariable()
Dim strMsg As String
strMsg = "This variable can't be used outside this procedure."
MsgBox strMsg
End Sub

Sub OutsideScope()
MsgBox strMsg
End Sub



Defining Private Module-Level Scope

You can define module-level variables and constants in the Declarations
section of a module. Module-level variables can be either public or private.
Public variables are available to all procedures in all modules in a
project; private variables are available only to procedures in that module.
By default, variables declared with the Dim statement in the Declarations
section are scoped as private. However, by preceding the variable with the
Private keyword, the scope is obvious in your code.

In the following example, the string variable strMsg is available to any
procedures defined in the module. When the second procedure is called, it
displays the contents of the string variable strMsg in a dialog box.

' Add following to Declarations section of module.
Private strMsg sAs String

Sub InitializePrivateVariable()
strMsg = "This variable can't be used outside this module."
End Sub

Sub UsePrivateVariable()
MsgBox strMsg
End Sub



Note Public procedures in a standard module or class module are available
to any referencing project. To limit the scope of all procedures in a module
to the current project, add an Option Private Module statement to the
Declarations section of the module. Public variables and procedures will
still be available to other procedures in the current project, but not to
referencing projects.



Defining Public Module-Level Scope

If you declare a module-level variable as public, it's available to all
procedures in the project. In the following example, the string variable
strMsg can be used by any procedure in any module in the project.

' Include in Declarations section of module.
Public strMsg As String



All procedures are public by default, except for event procedures. When
Visual Basic creates an event procedure, the Private keyword is
automatically inserted before the procedure declaration. For all other
procedures, you must explicitly declare the procedure with the Private
keyword if you do not want it to be public.

You can use public procedures, variables, and constants defined in standard
modules or class modules from referencing projects. However, you must first
set a reference to the project in which they are defined.

Public procedures, variables, and constants defined in other than standard
or class modules, such as form modules or report modules, are not available
to referencing projects, because these modules are private to the project in
which they reside.

======================
From the flavor of your questions is seems you are just getting started with
Access. If that is true and you intend to be a serious developer with it
then you have a lot of learning to do.

Read books, lurk the newsgroups, there are a bunch of them and most of them
have a very specific focus.

My reference to a naming convention seems to have shot right by you. one of
the elements of a naming conventions can be scope indicators in the variable
names.

Good luck.

HTH
 
P

Peter J. Veger

Douglas J. Steele said:
It's possible to set a default value of Date (or Now) for fields. What
happens when you try?

Sorry, my mistake, I meant:

In the Design View form of tables, it is possible to assign to the Default
Value of a field a call to a standard VBA-function such as Date, but not a
call of a user-defined function (of course public, in whatwever type of
module).

My problem: where can I find the specification of these restrictions in the
Design View forms of tables/forms/reports?

peter veger, best,netherlands
 
P

Peter J. Veger

I have had a 30-year career in IT at academic level, have been using Access
since version 3 (I believe).
But: I am using each week several programming languages and tens of
applications.
What I hate is that I have to guess all those simple details.
(e.g. what is the string quote in VBA, JScript, C#, Haskell, Delphi, Caml,
etc; what should I use as newline; ...)
For some of these languages it is simple to find the answer --- they have an
authoritative specification with a clear structure---, for some it is very
difficult.

My question here concerns the Design View forms used to define
Tables/Forms/Reports and not the code in modules. So I am not speaking about
"for use by another procedure" or method.

Although your reply does not help me, I am grateful for your care,

peter veger, best, the netherlands
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top