HOWTO: Change the Name of a Microsoft Access Field w/MFC DAOLast reviewed: June 26, 1997Article ID: Q152688 |
The information in this article applies to:
SUMMARYThe MFC DAO classes do not provide a programmatic way to change the name of a Microsoft Access field. The example code in this article changes a field's Name property by directly calling DAO using the m_pDAOFields data member of CDaoTableDef.
MORE INFORMATION
Sample Code
/////////////////////////////////////////////////////////////////// // CTabDef - class definition class CTabDef : public CDaoTableDef { public: CTabDef( CDaoDatabase* pDB) : CDaoTableDef( pDB ) { } ~CTabDef() {} void ChangeFieldProperty(LPCTSTR szOldName, LPCTSTR szNewName); }; ///////////////////////////////////////////////////////////////// // CTabDef - implementation void CTabDef::ChangeFieldProperty( LPCTSTR szOld, LPCTSTR szNew ) { // To be used as an "in" param to get_Item DAOField* pDAOField = NULL; if (m_pDAOFields == NULL) InitFieldsCollection(); // Enumerate the fields collection and find the field. // Then replace the name property with the new string. try { DAO_CHECK( m_pDAOFields->get_Item( COleVariant(szOld, VT_BSTRT), &pDAOField ) ); DAO_CHECK( pDAOField->put_Name( COleVariant(szNew, VT_BSTRT).bstrVal ) ); } catch( CDaoException* e ) { AfxMessageBox( e->m_pErrorInfo->m_strDescription ); goto term; } catch(...) { AfxMessageBox( _T( "unknown exception" ) ); goto term; } term: if( pDAOField ) pDAOField->Release(); } |
Keywords : kbcode kbprg MfcDAO
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |