Microsoft KB Archive/113332

= FIX: AddNew Method Gives Error: Illegal Function Call =

Article ID: 113332

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q113332



SYMPTOMS
It is possible to receive an "Illegal Function Call" error message in response to an AddNew method. This article demonstrates how this error can occur and how to work around it.



CAUSE
The cause of this problem has not yet been determined. We're researching it.



WORKAROUND
There are two ways to work around this problem. The first method is to move to the last record before adding the record. The following code demonstrates this work around: Form1.AutoRedraw = True Data1.DatabaseName = "DB.MDB" Data1.RecordSource = "SELECT * FROM Table1 WHERE Field1 = 'Record1'" Data1.Refresh Data1.Recordset.MoveLast Print "ReadOnly "; Data1.ReadOnly Print "Options "; Data1.Options Print "Updatable "; Data1.Recordset.Updatable Data1.Recordset.AddNew The other method is to delete the index. In the previous example, you would delete Index1.



STATUS
Microsoft has confirmed this to be a bug in Microsoft Visual Basic version 3.0 for Windows. This problem has been corrected in Visual Basic version 4.0.



MORE INFORMATION
A problem with the Microsoft Access database engine can cause an "Illegal Function Call" error when adding a record to a database. This error should not occur. This problem is not related to the data control and can also occur when using methods from the Professional Edition of Visual Basic version 3.0.

Steps to Reproduce Problem
  Use the Data Manager to create a database with these characteristics: DATABASE: DB.MDB TABLES:  Table1 FIELDS:  Field1 in Table1 INDEXES: Index1 on Field1 not Unique and not Primary  Add two records to Table1 with values of "Record1" and "Record2" for Field1. Start a new project in Visual Basic. Form1 is created by default. Add a data control (Date1) and a command button (Command1) to the form.  Add the following code to the command button's click event: Sub Command1_Click Form1.AutoRedraw = True Data1.DatabaseName = "DB.MDB" Data1.RecordSource = "SELECT * FROM Table1 WHERE Field1 = 'Record1'" Data1.Refresh Print "ReadOnly "; Data1.ReadOnly Print "Options "; Data1.Options Print "Updatable "; Data1.Recordset.Updatable Data1.Recordset.AddNew End Sub </li> Run the code and click the Command1 button. You should receive the "Illegal function call" error on the on the Addnew line.</li></ol>

Additional query words: buglist3.00 3.00 buglist3.00 fixlist4.00

Keywords: kbbug kbfix KB113332

-

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

© Microsoft Corporation. All rights reserved.