
Can't open database file unless filed count matches
I have a Microsoft Access file named Myfile.mdb.
I am using the following code to see if the file has the correct number of
fields.
CDaoRecordset set;
set.Open(dbOpenDynaset);
CDaoTableDef ( set.m_pDatabase);
daoTable.Open(_T("Myfile"));
int nFieldCount = daoTable.GetFieldCount(); // check for correct count
I have recently added a field (or column) to Myfile.mdb, thus yielding a
correct count of six fields.
I am using GetFieldCount() to determine if a 'new' file is being used. The
old version of Myfile.mdb had only five fields.
Here's the problem.
I had hoped to be able to open the older files (with one less field), then
add the new field with CreateField(). But I get a try/catch CDaoException
indicating I have one too few columns in the file I am trying to open.
Does anyone know how I can open these older files to make my application
backward compatible for my customers? In other words, I want to open the
older Myfile.mdb files and if they have five fields, then one will be added
with CreateField().
Any help would be greatly appreciated.
Michael