PRB: GetChunk & AppendChunk Not Allowed on Non-Memo Fields

Last reviewed: June 21, 1995
Article ID: Q113949
The information in this article applies to:

- Professional Edition of Microsoft Visual Basic for Windows,

  versions 3.0

SYMPTOMS

The GetChunk and AppendChunk methods allow a Visual Basic program to move information in and out of Memo or Long Binary fields in a RecordSet. Using these methods with other fields types may cause a general protection (GP) fault. However, the more likely result is trappable error 3259 "Invalid field data type."

CAUSE

The GetChunk, AppendChunk, and FieldSize methods are only applicable to Memo or Long Binary type fields. If the field type is not checked before using one of these methods, the inappropriate use of these methods may cause a GP fault or a trappable error message.

RESOLUTION

To avoid this problem, check the field's Type property before using any of these methods. These methods should only be used as they are intended to be used on Memo or Long Binary type fields.

MORE INFORMATION

A GP fault is not consistent due to memory mapping, so it is possible (but highly unlikely) that an .EXE may be produced with this problem without the programmer knowing that the .EXE is not working correctly.

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a command button (Command1) to the form.

  3. Add the following code to the Command1_Click procedure.

       Sub Command1_Click ()
          Dim DB As Database
          Dim DS As Dynaset
          Set DB=OpenDatabase("C:\VB\BIBLIO.MDB")
          Set DS=DB.CreateDynaset("Authors")
          Debug.Print DS("Author").GetChunk(0,50)  ' fieldname's type <> memo
       End Sub
    
    

  4. Start the program (or press the F5 key). Click the Command1 button. This may produce a GP Fault. However, the more likely result is trappable error 3259 "Invalid field data type," as expected.

Steps to Solve the Problem

  1. Replace the code in the above example with the following if you are using database objects:

       Sub Command1_Click ()
          Const DB_MEMO = 12
          Dim DB As Database
          Dim DS As Dynaset
          Set DB=OpenDatabase("C:\VB\BIBLIO.MDB")
          Set DS=DB.CreateDynaset("Authors")
          If DB.TableDefs("Authors").Fields("Author").Type = DB_MEMO Then
             Debug.Print DS("Author").GetChunk(0,50)
          Else
             Form1.Print "Wrong Field Type"
          End If
       End Sub
    
       Or replace it with the following if you are using a Data control:
    
       Sub Command1_Click ()
          Const DB_MEMO = 12
          Data1.Databasename = "C:\VB\BIBLIO.MDB"
          Data1.RecordSource = "Authors"
          Data1.Refresh
          ' Enter the following two lines as one, single line:
          If Data1.Database.TableDefs("Authors").Fields("Author").Type =
             DB_MEMO Then
             Debug.Print Data1.RecordSet("Author").GetChunk(0,50)
          Else
            Form1.Print "Wrong Field Type"
          End If
       End Sub
    
       This code will avoid using the inappropriate GetChunk method on the
       Author field because its type is DB_TEXT (value 10).
    
    

  2. Start the program (or press the F5 key). Click the Command1 button.


Additional reference words: 3.00 GPF
KBCategory: kbprg kbcode kbprb
KBSubcategory: APrgDataOther


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: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.