Article ID: 180611
Article Last Modified on 12/8/2003
fi.m_strDefaultValue = _T("11North");
and then call CDaoTableDef::CreateField(fi), DAO throws an exception
reporting:
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:
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".
void setFI( CDaoFieldInfo &fi)
{
fi.m_strName = _T("testfield");
fi.m_nType = dbText;
fi.m_lSize = 50;
fi.m_lAttributes = dbFixedField;
fi.m_nOrdinalPosition = 2;
fi.m_bRequired = FALSE;
fi.m_bAllowZeroLength = TRUE;
fi.m_lCollatingOrder = dbSortGeneral ;
// fi.m_strDefaultValue = _T("\"11North\""); // Corrects the error.
fi.m_strDefaultValue = _T("11North"); // Displays the error.
}
void CMy1aDlg::OnBUTcreateTbl()
{
CDaoDatabase db;
try
{
db.Open(_T("c:\\db1.mdb"));
CDaoTableDef td(&db);
td.Create(_T("FieldTest"));
CDaoFieldInfo fi;
setFI( fi);
td.CreateField(fi);
td.Append();
CDaoRecordset rs(&db);
rs.Open(dbOpenDynaset, _T("Select * from FieldTest"));
rs.AddNew();
rs.Update();
rs.Close();
db.Close();
}
catch(CDaoException *de)
{
CString strMsg;
strMsg.Format(
_T("ERROR:CDaoException\n\n")
_T("SCODE_CODE =%d\n")
_T("SCODE_FACILITY =%d\n")
_T("SCODE_SEVERITY =%d\n")
_T("ResultFromScode =%d\n"),
SCODE_CODE (de->m_scode),
SCODE_FACILITY (de->m_scode),
SCODE_SEVERITY (de->m_scode),
ResultFromScode (de->m_scode));
AfxMessageBox(strMsg);
de->Delete();
}
}
To reproduce this problem in Access, open up a table in Design View. In the
Default Value Edit field, enter 1abc (without quotation marks) and then
click on another field.
Keywords: kbprb KB180611