Microsoft KB Archive/113949

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

Article ID: 113949

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q113949



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
 Start a new project in Visual Basic. Form1 is created by default. Add a command button (Command1) to the form.  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  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
  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). </li> Start the program (or press the F5 key). Click the Command1 button.</li></ol>

Additional query words: 3.00 GPF

Keywords: kbprb KB113949

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.