Microsoft KB Archive/173649: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 51: | Line 51: | ||
== CAUSE == | == CAUSE == | ||
The called procedure may be declaring the recordset | The called procedure may be declaring the recordset "As Object" instead of "As Recordset". | ||
</div> | </div> | ||
Line 58: | Line 58: | ||
== RESOLUTION == | == RESOLUTION == | ||
Change the declaration in the called procedure to | Change the declaration in the called procedure to "As Recordset". | ||
</div> | </div> | ||
Line 101: | Line 101: | ||
Dim db As Database, rs As Recordset | Dim db As Database, rs As Recordset | ||
Set db = DBEngine(0).OpenDatabase _ | Set db = DBEngine(0).OpenDatabase _ | ||
( | ("c:\office\access20\sampapps\nwind.mdb") ' alter as needed | ||
Set rs = db.OpenRecordset( | Set rs = db.OpenRecordset("Table1") | ||
rs.Index = | rs.Index = "PrimaryKey" | ||
Test_Call rs | Test_Call rs | ||
rs.Close | rs.Close | ||
Line 113: | Line 113: | ||
K1 = 1234 | K1 = 1234 | ||
K2 = 22222 | K2 = 22222 | ||
K3(0) = | K3(0) = "abc" | ||
K3(1) = | K3(1) = "def" | ||
K3(2) = | K3(2) = "ghi" | ||
K3(3) = | K3(3) = "jkl" | ||
Debug.Print | Debug.Print "Pass 1" | ||
For I = 0 To 3 | For I = 0 To 3 | ||
rs.Seek | rs.Seek "=", K1, K2, K3(I) | ||
Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) | Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) | ||
Next I | Next I | ||
Debug.Print | Debug.Print "Pass 2" | ||
For I = 0 To 3 | For I = 0 To 3 | ||
rs.Seek | rs.Seek "=", K1, K2, K3(I) | ||
Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) | Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) | ||
Next I | Next I | ||
Debug.Print | Debug.Print "Pass 3" | ||
For I = 0 To 3 | For I = 0 To 3 | ||
rs.Seek | rs.Seek "=", K1, K2, K3(I) | ||
Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) | Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) | ||
Next I | Next I | ||
Line 142: | Line 142: | ||
=== Workaround === | === Workaround === | ||
Change | Change "Sub Test_Call (rs As Object)" to "Sub Test_Call(rs As Recordset)".<br /> | ||
<br /> | <br /> | ||
'''NOTE''': This problem does not appear in Visual Basic 4.0 32-bit. | '''NOTE''': This problem does not appear in Visual Basic 4.0 32-bit. |
Latest revision as of 11:06, 21 July 2020
Article ID: 173649
Article Last Modified on 1/8/2003
APPLIES TO
- Microsoft Visual Basic 4.0 Professional Edition
This article was previously published under Q173649
SYMPTOMS
When passing a recordset to another Sub or Function, you see memory corruption or may experience a general protection fault (GP fault) in Vba5.dll.
CAUSE
The called procedure may be declaring the recordset "As Object" instead of "As Recordset".
RESOLUTION
Change the declaration in the called procedure to "As Recordset".
STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION
Microsoft provides code examples for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
This code is provided 'as is' and Microsoft does not guarantee that the following code can be used in all situations. Microsoft does not support modifications of the code to suit customer requirements for a particular purpose.
Steps to Reproduce Behavior
In Microsoft Access 2.0 or another front-end, create a Jet 2.x database (or use NWIND or BIBLIO) and add the following table:
Table: Table1 Field: K1 Long Field: K2 Long Field: K3 Text (3) Field: Desc Text
- Make a composite primary key, consisting of K1, K2, and K3, and then save the table design.
Add the following data:
K1 K2 K3 Desc 1234 22222 abc xxxxxxxxxxx 1234 22222 def xxxxxxxxxxx 1234 22222 ghi xxxxxxxxxxx 1234 22222 jkl xxxxxxxxxxx
- Create a Visual Basic 4.0 16-bit application.
- Add a command button (Command1) to the form.
Add the following code to the form:
option Explicit Private Sub Command1_Click() Dim db As Database, rs As Recordset Set db = DBEngine(0).OpenDatabase _ ("c:\office\access20\sampapps\nwind.mdb") ' alter as needed Set rs = db.OpenRecordset("Table1") rs.Index = "PrimaryKey" Test_Call rs rs.Close db.Close End Sub Sub Test_Call(rs As Object) Dim K1 As Long, K2 As Long, K3(3) As String, I As Long K1 = 1234 K2 = 22222 K3(0) = "abc" K3(1) = "def" K3(2) = "ghi" K3(3) = "jkl" Debug.Print "Pass 1" For I = 0 To 3 rs.Seek "=", K1, K2, K3(I) Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) Next I Debug.Print "Pass 2" For I = 0 To 3 rs.Seek "=", K1, K2, K3(I) Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) Next I Debug.Print "Pass 3" For I = 0 To 3 rs.Seek "=", K1, K2, K3(I) Debug.Print I; K1; K2; K3(0), K3(1), K3(2), K3(3) Next I End Sub
- Make sure you change the .OpenDatabase method to correctly point to the database.
- Run the application and click the command button. You may need to do this several times to see the error.
Result
You should see either intermittent and worsening corruption of variables in the Debug Window, or you may get a GP fault in Vba5.dll.
Workaround
Change "Sub Test_Call (rs As Object)" to "Sub Test_Call(rs As Recordset)".
NOTE: This problem does not appear in Visual Basic 4.0 32-bit.
Additional query words: late-bound late bound vb4
Keywords: kb16bitonly kbprb KB173649