Default Value of a Field

M

Michael Volz

To All on MSDN VB Discussion Forum:

Is it possible to make the default value of a field equal
to the value of another field or fields of the same record
in the current table? If so, where would this information
be placed in the table design and what would the syntax be
to accomplish this task? Any help or hints on this topic
would be greatly appreciated. Thanks in advance.
 
T

Tim Ferguson

To All on MSDN VB Discussion Forum:

Is it possible to make the default value of a field equal
to the value of another field or fields of the same record
in the current table?

No: at the time that the DefaultValue is being assigned, there are no other
values in any other fields (it's a new record, geddit?), so those values
cannot be used. The DefaultValue can only see constants and a few database
functions like DATE() and so on.
If so, where would this information
be placed in the table design and what would the syntax be
to accomplish this task? Any help or hints on this topic
would be greatly appreciated.

Depending what you want to achieve, there are various Form events that can
be used to write helpful stuff into the textboxes. The Form_BeforeUpdate or
Control_LostFocus are usually the most helpful ones.

Bear in mind that often this question is asked in order to create a
"calculated field" but that is always a bad thing to do.

Hope that helps


Tim F
 
J

John Vinson

To All on MSDN VB Discussion Forum:

Is it possible to make the default value of a field equal
to the value of another field or fields of the same record
in the current table?

No. Defaults cannot refer to any other field; to do so would violate
third normal form. In addition, default values are applied the instant
a new record is created - the value of the other fields is unknown.
If so, where would this information
be placed in the table design and what would the syntax be
to accomplish this task? Any help or hints on this topic
would be greatly appreciated. Thanks in advance.

If you need to do this, you'll need to use VBA code in a Form that
you're using for data entry, perhaps in the AfterUpdate events of the
field or fields which define the default.
 

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