PRB: Cannot Set Default Value for Access (Jet) Text Fields (180611)
The information in this article applies to:
- The DAO SDK, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
- The Microsoft Foundation Classes (MFC)
This article was previously published under Q180611 SYMPTOMS
If you try to set the default value for a text field with a string that
starts with a number (for example, 11North), you will get an error. If you
set the DAO Struct CDaoFieldInfo fi field member as:
fi.m_strDefaultValue = _T("11North");
and then call CDaoTableDef::CreateField(fi), DAO throws an exception
reporting:
Syntax error (missing operator) in table-level validation expression.
(3320)
If you open the Access table in Design View, click the General Tab, and try
to enter 11North in the Default Value field, Access displays an error
dialog box with the message:
The Expression you have entered contains invalid syntax.
You may have entered an operand without an operator.
CAUSE
The error occurs because Access accepts expressions for the default value.
(Expressions are operators, constants, functions, literal values, and so
on.) When the default value begins with a number, Access tries to store the
default as a number.
RESOLUTION
You must use double quotes so that Access knows the default value is a
string. For example, to do this programmatically, the code is:
fi.m_strDefaultValue = _T("\"11North\"");
If you are working directly with an Access table in Design View, you must
start the string with a quote. For example, "11North".
Modification Type: | Major | Last Reviewed: | 12/8/2003 |
---|
Keywords: | kbprb KB180611 |
---|
|