DAO & Error 3314 
Author Message
 DAO & Error 3314

I am developing an MFC application using DAO. I have an Access 97 database
file and I manipulate it from my MFC application. I have a CDaoRecordset
derived class generated by class wizard connected to a database table in the
Access database file. In this database table there are several fields and
one of them is a Text field called "Mnemonic". I set both the 'Required' and
'Allow Zero Length' properties to Yes. Which means a value must be provided
to this field and it can be an empty string "".

Here is a piece of code:

class CRecordsetBasicAttributtes : public CDaoRecordset
CRecordsetBasicAttributtes (CDaoDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(CRecordsetBasicAttributtes )

// Field/Param Data
//{{AFX_FIELD(CRecordsetBasicAttributtes , CDaoRecordset)
CString m_strMnemonic;



Pseudo code for creating a new record:


    CRecordsetBasicAttributtes basicAttr(m_pDB);

    // Open the record set

    // Create a new record

   // fill the m_strMnemonic
   basicAttr.m_strMnemonic=_T("Put some string here");  //<<< the important

    // Save the changes

    // Close the record set


When I assign an empty string _T("") to 'basicAttr.m_strMnemonic' and call
'basicAttr.Update()' I will get a DAO exception:

"The field <name> can't contain a Null value because the Required property
for this field is set to True. Enter a value in this field. (Error 3314)"

I do not understand why because although the required property is set to Yes
in the Access database file the Allow Zero Length property set to Yes too.
That is the zero length string is all right for this field.

How can I put empty strings into the database text fields (using MFC) which
have both
'Required' & 'Allow Zero Length' properties are set to Yes.

Please, help me solve this problem.

Sat, 10 Mar 2001 03:00:00 GMT  
 DAO & Error 3314
Hi Attila,

There are two possible solutions to your problem:

1)    Set the field's "default value" to an empty string (within Access).

2)    Force the field to be updated using SetFieldDirty.
    basicAttr.SetFieldDirty( &basicAttr.m_strMnemonic, TRUE );

This problem occurs because when you AddNew to a recordset DAO creates a
record buffer (using the table's rules) and this fields value is most likely
null.  When you assign an empty string you aren't making any changes to the
field's member variable (CStrings' can't represent Null so it's empty).
When Update is called it sees that the field hasn't changed so the field is
not updated which causes your error.

Frank Hickman
NobleSoft, Inc.


Sat, 10 Mar 2001 03:00:00 GMT  
 DAO & Error 3314
In Database Land there is a distinction between NULL and the empty string.
I'm not sure how to force DAO to insert the empty string when the C/C++
code passes a null string.  I know that you can specify the NULL keyword in
a SQL INSERT statment, so there might be an equivalent EMPTY keyword.

I guess I don't understand why you want to require a field but allow the
user to fill it with nothing.  I think the idea behind putting the NULL
value in a field is that it saves space in the database, but I could be

Sun, 11 Mar 2001 03:00:00 GMT  
 [ 3 post ] 

 Relevant Pages 

1. mfc DAO errors 3167 & 3159

2. Linker error 2001 @&(#&@#&$@

3. Linker error 2001 @&(#&@#&$@

4. scanf() && printf() error

5. Spin Control & DAO

6. DAO & Indexes - Adding records/Current record

7. MFC-DAO & Dealing with passwords

8. DAO & Visual 4.2

9. DBCombo & DAO


11. DAO & SpinCtrl

12. DAO & Locking


Powered by phpBB® Forum Software