Microsoft KB Archive/117611

= ACC2: GPF Using GetChunk Method As Argument for Put Statement =

Article ID: 117611

Article Last Modified on 7/8/2002

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q117611



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you use the GetChunk method in the third parameter of a Put statement, you may receive a general protection (GP) fault.



CAUSE
The third parameter of the Put statement requires a variable name. You cannot directly use a method (such as the GetChunk method) as a statement argument.



RESOLUTION
Create an intermediate variable, assign the value returned from the GetChunk method to this variable, and then use the variable as the third parameter of the Put statement. This technique is demonstrated in the "Workaround" section later in this article.



STATUS
Microsoft has confirmed this to be a problem in Microsoft Access version 2.0. This problem no longer occurs in Microsoft Access version 7.0.



Steps to Reproduce Problem
WARNING: Following these steps will cause a general protection fault on your computer. Make sure you save and close any open work on your computer before following these steps.

 Start Microsoft Access and open the sample database NWIND.MDB.  Create a new module and enter the following function:

Function Test Dim d As Database, rs As Recordset

Set d = CurrentDb Set rs = d.OpenRecordset("Employees", DB_OPEN_TABLE)

Open rs![Last Name] & ".txt" For Binary As #1 Put #1,, rs![Notes].GetChunk(0, 1000) Close #1 rs.Close d.Close End Function  From the View menu, choose Immediate window. Type the following line in the Immediate window, and then press ENTER:

?Test

Note that you receive a GP fault.</ol>

Workaround
The following sample function is a modified version of the Test function above. This version of the Test function will generate a text file with a portion of the Notes memo field from the first record of the Employees table. The name of the text file is determined by the first eight characters of the Last Name field. Note that in this version, the Put statement uses the variable X for the third parameter, which is set equal to the GetChunk method.

Function test Dim d As Database, rs As Recordset Dim x As String

Set d = CurrentDb Set rs = d.OpenRecordset("Employees", DB_OPEN_TABLE)

Open rs![Last Name] & ".txt" For Binary As #1 x = rs![Notes].GetChunk(0, 1000) Put #1,, x        Close #1 rs.Close d.Close

End Function

<div class="references_section">