SAMPLE: DAOPROP.EXE Sets a Custom Property on an Access Database with MFC DAO

ID: Q237285


The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, version 6.0


SUMMARY

DAOPROP.exe is a sample that demonstrates adding a custom property to an Access database by using the MFC DAO classes and the underlying DAO OLE interfaces. It is based on article Q178745 that demonstrates the same concept by using Visual Basic for Applications in Access 97.
The MFC DAO classes expose a subset of the DAO hierarchy directly. The MFC DAO classes do not, however, expose all of the functionality available to developers using Visual Basic, Visual Basic for Applications or the DAO SDK in Visual C++. It is possible to use the complete hierarchy indirectly by using the underlying DAO OLE interfaces that the MFC DAO classes wrap.
For a description of using the DAO OLE interfaces see MFC technical note #54 in the Microsoft Developer Network (MSDN).


MORE INFORMATION

The DAO interfaces are defined in the file DBDAOINT.h in your \VC98\Include directory. When using the DAO OLE interfaces, it is often necessary to use the VARIANT and BSTR data types. These can be conveniently manipulated by using the wrapper class COleVariant. To initialize a VARIANT object with a BSTR string, it is necessary to use the VT_BSTRT type specified to make sure that the string is created as an ANSI string in ANSI builds, and as a UNICODE string in UNICODE builds. For more information about strings and DAO refer to article Q140599.
For a demonstration of initializing a COleVariant object and extracting values from it see the DAOVIEW sample in the MSDN.

The project included in the self-extracting executable is an MFC single document project. Its functionality is contained in the three menu handlers OnPropertyCreate(), OnPropertyGet(), and OnPropertySet(). These functions call the functions CreateCustomProp(), GetCustomProp(), and SetCustomProp() respectively.
Several concepts are demonstrated by this sample:

  • Creating a COleVariant of type VT_BSTRT in OnPropertyCreate() and OnPropertyGet().


  • Using the V_BSTRT macro to extract a string from a COleVariant in OnPropertyGet().


  • Using the DAO OLE interfaces in CreateCustomProp(), GetCustomProp(), and SetCustomProp().


  • Using the DAO_CHECK() macro to test the success of a DAO call and throw an exception in case of failure.


  • Using the TRY, CATCH_ALL, END_CATCH_ALL and THROW_LAST macros to correctly handle exceptions when using the DAO OLE interfaces.


To check the custom property in your Access database file, open the file in Access 97, go to File - Database Properties and select on the Custom tab.
The following file is available for download from the Microsoft Software Library. Click the file name below to download the file:
DaoProp.exe
Release Date:

For more information about how to download files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services
FileName Size
DaoProperty.asp 42.8KB
DaoProperty.clw 1.54KB
DaoProperty.cpp 3.34KB
DaoProperty.dsp 4.42KB
DaoProperty.dsw 545 bytes
DaoProperty.h 1.23KB
DaoProperty.ncb 57.0KB
DaoProperty.opt 47.5KB
DaoProperty.rc 9.74KB
DaoPropertyDoc.cpp 9.25KB
DaoPropertyDoc.h 1.68KB
DaoPropertyView.cpp 1.67KB
DaoPropertyView.h 1.61KB
db1.mdb 58.0KB
MainFrm.cpp 1.70KB
MainFrm.h 1.37KB
resource.h 739 bytes
StdAfx.cpp 213 bytes
StdAfx.h 1.19KB
DaoProperty.ico 1.05KB
DaoProperty.rc2 403 bytes
DaoPropertyDoc.ico 1.05KB


REFERENCES

For additional information about using DAO functions, please click the article number(s) below to view the article(s) in the Microsoft Knowledge Base:

Q178745 ACC: Using DAO to Set and Retrieve Custom Database Properties
Q140599 PRB: MFC DAO Functions Accepting COleVariant Strings May Fail
For more information, please see the DAOVIEW sample located on the MSDN Web Workshop: DAOVIEW sample in the MSDN

Additional query words:

Keywords : kbfile kbsample kbDAO kbVC kbVC600 kbGrpVCDB kbDSupport
Version : winnt:6.0
Platform : winnt
Issue type : kbhowto


Last Reviewed: August 23, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.