DOCUMENT:Q190522 07-AUG-1998 [vbwin] TITLE :PRB: Error Setting Field Format Property of Access Tables PRODUCT :Microsoft Visual Basic for Windows PROD/VER: OPER/SYS:WINDOWS KEYWORDS: ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, versions 4.0, 5.0, 6.0 --------------------------------------------------------------------- SYMPTOMS ======== From Visual Basic, when trying to specify a field Format property of an Access table (for example, field type DateTime) from blank to "Long Date" format, the following error occurs: Run-time error '3421': Data type conversion error. CAUSE ===== The property data type constant should always be "dbText." If other data type constants, such as dbDate or dbNumeric are specified, you will encounter the error described above. STATUS ====== This behavior is by design. MORE INFORMATION ================ The following Visual Basic 5.0 example creates a new field object MyNewDate with data type dbDate, and appends it to the Fields collection. It then specifies the Format property with the value "Long Date." Note that the Format property is specified as "dbDate," which is incorrect. To correct the problem, you should change: Set prp = fld.CreateProperty("Format", dbDate) to: Set prp = fld.CreateProperty("Format", dbText) Steps to Reproduce Behavior --------------------------- 1. Start a "Standard EXE" project in Visual Basic. Form1 is created by default. 2. From the Project menu, select References, and then place a check next to Microsoft DAO 3.5 Object Library. In Visual Basic 4.0, you can reference Microsoft DAO Object Library from Tools menu, then select References. 3. Add a CommandButton control, Command1, to Form1. 4. Paste the following code in the Command1_Click() code snippet: Dim db As Database Dim tdf As TableDef Dim fld As Field Dim prp As Property Set db = OpenDatabase("Nwind.mdb") Set tdf = db.TableDefs("Employees") tdf.Fields.Append tdf.CreateField("MyNewDate", dbDate) 'Error line Set fld = tdf.Fields("MyNewDate") Set prp = fld.CreateProperty("Format", dbDate) prp.Value = "Long Date" fld.Properties.Append prp REFERENCES ========== For more information please reference the following articles: ARTICLE ID: Q170549 TITLE : HOWTO: Read or Modify User-Defined DAO Properties ARTICLE ID: Q178745 TITLE : ACC: Using DAO to Set and Retrieve Custom Data Properties Additional query words: kbdse kbDSupport kbVBp kbVBp400 kbVBp500 kbVBp600 kbDAO350 kbDatabase ====================================================================== Platform : WINDOWS Issue type : kbprb ============================================================================= 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. Copyright Microsoft Corporation 1998.