FIX: "Item not found in this collection" Message Box

Last reviewed: September 19, 1997
Article ID: Q148848
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Edition, version 4.0

SYMPTOMS

When you try to add or update a record by using the MFC DAO Database classes, message box may appear with this message:

   Item not found in this collection.

CAUSE

MFC calls put_Collect() a DAO function in CDaoRecordset::SetFieldValue(). This function does not expect square brackets to be included as part of the field name. The Visual C++ Wizards place square brackets around the field names of your recordset by default in the DoFieldExchange() method of your CDaoRecordset. This allows the user to have field names that contain spaces.

Earlier versions of DAO allowed square brackets to be passed with the field name used in the put_Collect() call. DAO version 3.000.2504, which is installed by some programs such as Microsoft Word 7a, does not allow the square brackets. You can check the version of DAO on your computer by looking at the version of Dao3032.dll. (Press ALT+ENTER in the Program Manager or look at the properties of the DLL.)

RESOLUTION

In Visual C++ 4.1, MFC DAO has been modified so that it removes brackets from field names prior to calling into the DAO DLL. Additionally, the Dao3032.dll that ships with Visual C++ 4.1 now tolerates brackets in field names.

To work around the problem in Visual C++ 4.0 applications, intercept MFC and strip the square brackets before passing the field name to the put_Collect() call. To do this, override CDaoRecordset::SetFieldValue(). See the "Code to Strip Square Brackets" section in this article for an example.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Visual C++ version 4.1.

MORE INFORMATION

Sample Code to Strip Square Brackets

   void CYourRecordSet::SetFieldValue(LPCTSTR lpszName,
       const COleVariant& varValue)
   {
       ASSERT_VALID(this);
       ASSERT(IsOpen());
       ASSERT(m_pDAORecordset != NULL);

       LPTSTR lpszModifiedName = NULL;

       if (*lpszName == '[')
       {

           lpszModifiedName = new TCHAR[_tcslen(lpszName) + 1];
           StripBrackets(lpszName,lpszModifiedName);
           lpszName=lpszModifiedName;
       }

       DAO_CHECK(m_pDAORecordset->put_Collect(
           COleVariant(lpszName, VT_BSTRT), varValue));

       delete lpszModifiedName;
   }

Keywords          : MfcDAO kbprg kbsample kbbuglist kbfixlist
Technology        : kbMfc
Version           : 4.00
Platform          : NT WINDOWS
Solution Type     : kbfix


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.